comparison gtk3/dw.c @ 2855:86286f528adf

Fix new safety warnings reported by the new GCC on Linux. The semaphore code is used on other platforms... make sure all platforms using this code are the same.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 15 Nov 2022 03:50:00 +0000
parents 8a5131cbbe93
children 59106bf7f9f4
comparison
equal deleted inserted replaced
2854:8a5131cbbe93 2855:86286f528adf
8603 *eve = NULL; 8603 *eve = NULL;
8604 8604
8605 return DW_ERROR_NONE; 8605 return DW_ERROR_NONE;
8606 } 8606 }
8607 8607
8608 struct _seminfo { 8608 struct _dw_seminfo {
8609 int fd; 8609 int fd;
8610 int waiting; 8610 int waiting;
8611 }; 8611 };
8612 8612
8613 static void _handle_sem(int *tmpsock) 8613 static void _dw_handle_sem(int *tmpsock)
8614 { 8614 {
8615 fd_set rd; 8615 fd_set rd;
8616 struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); 8616 struct _dw_seminfo *array = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo));
8617 int listenfd = tmpsock[0]; 8617 int listenfd = tmpsock[0];
8618 int bytesread, connectcount = 1, maxfd, z, posted = 0; 8618 int bytesread, connectcount = 1, maxfd, z, posted = 0;
8619 char command; 8619 char command;
8620 sigset_t mask; 8620 sigset_t mask;
8621 8621
8658 return; 8658 return;
8659 } 8659 }
8660 8660
8661 if(FD_ISSET(listenfd, &rd)) 8661 if(FD_ISSET(listenfd, &rd))
8662 { 8662 {
8663 struct _seminfo *newarray; 8663 struct _dw_seminfo *newarray;
8664 int newfd = accept(listenfd, 0, 0); 8664 int newfd = accept(listenfd, 0, 0);
8665 8665
8666 if(newfd > -1) 8666 if(newfd > -1)
8667 { 8667 {
8668 /* Add new connections to the set */ 8668 /* Add new connections to the set */
8669 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1)); 8669 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1));
8670 memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount)); 8670 memcpy(newarray, array, sizeof(struct _dw_seminfo)*(connectcount));
8671 8671
8672 newarray[connectcount].fd = newfd; 8672 newarray[connectcount].fd = newfd;
8673 newarray[connectcount].waiting = 0; 8673 newarray[connectcount].waiting = 0;
8674 8674
8675 connectcount++; 8675 connectcount++;
8685 { 8685 {
8686 if(FD_ISSET(array[z].fd, &rd)) 8686 if(FD_ISSET(array[z].fd, &rd))
8687 { 8687 {
8688 if((bytesread = read(array[z].fd, &command, 1)) < 1) 8688 if((bytesread = read(array[z].fd, &command, 1)) < 1)
8689 { 8689 {
8690 struct _seminfo *newarray; 8690 struct _dw_seminfo *newarray;
8691 8691
8692 /* Remove this connection from the set */ 8692 /* Remove this connection from the set */
8693 newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1)); 8693 newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount-1));
8694 if(!z) 8694 if(!z)
8695 memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1)); 8695 memcpy(newarray, &array[1], sizeof(struct _dw_seminfo)*(connectcount-1));
8696 else 8696 else
8697 { 8697 {
8698 memcpy(newarray, array, sizeof(struct _seminfo)*z); 8698 memcpy(newarray, array, sizeof(struct _dw_seminfo)*z);
8699 if(z!=(connectcount-1)) 8699 if(z!=(connectcount-1))
8700 memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1)); 8700 memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1)));
8701 } 8701 }
8702 connectcount--; 8702 connectcount--;
8703 8703
8704 /* Replace old array with new one */ 8704 /* Replace old array with new one */
8705 free(array); 8705 free(array);
8805 free(tmpsock); 8805 free(tmpsock);
8806 return NULL; 8806 return NULL;
8807 } 8807 }
8808 8808
8809 /* Create a thread to handle this event semaphore */ 8809 /* Create a thread to handle this event semaphore */
8810 pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); 8810 pthread_create(&dwthread, NULL, (void *)_dw_handle_sem, (void *)tmpsock);
8811 return GINT_TO_POINTER(ev); 8811 return GINT_TO_POINTER(ev);
8812 } 8812 }
8813 8813
8814 /* Open an already existing named event semaphore. 8814 /* Open an already existing named event semaphore.
8815 * Parameters: 8815 * Parameters:
8933 * an open or create call. 8933 * an open or create call.
8934 */ 8934 */
8935 int dw_named_event_close(HEV eve) 8935 int dw_named_event_close(HEV eve)
8936 { 8936 {
8937 /* Finally close the domain socket, 8937 /* Finally close the domain socket,
8938 * cleanup will continue in _handle_sem. 8938 * cleanup will continue in _dw_handle_sem.
8939 */ 8939 */
8940 close(GPOINTER_TO_INT(eve)); 8940 close(GPOINTER_TO_INT(eve));
8941 return DW_ERROR_NONE; 8941 return DW_ERROR_NONE;
8942 } 8942 }
8943 8943