# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1668484200 0 # Node ID 86286f528adf43406987a5b0d23172fa9a112f6c # Parent 8a5131cbbe9320ab8e7f39d7390df4a09a1fe45f 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. diff -r 8a5131cbbe93 -r 86286f528adf dwtest.c --- a/dwtest.c Tue Nov 15 02:29:56 2022 +0000 +++ b/dwtest.c Tue Nov 15 03:50:00 2022 +0000 @@ -344,7 +344,7 @@ void draw_file(int row, int col, int nrows, int fheight, HPIXMAP hpma) { HPIXMAP hpm = hpma ? hpma : text2pm; - char buf[10]; + char buf[15] = {0}; int i,y,fileline; char *pLine; @@ -359,12 +359,12 @@ { fileline = i + row - 1; y = i*fheight; - dw_color_background_set(1 + (fileline % 15) ); + dw_color_background_set(1 + (fileline % 15)); dw_color_foreground_set(fileline < 0 ? DW_CLR_WHITE : fileline % 16); if(!hpma) { - sprintf( buf, "%6.6d", i+row ); - dw_draw_text( 0, text1pm, 0, y, buf); + snprintf(buf, 15, "%6.6d", i+row); + dw_draw_text(0, text1pm, 0, y, buf); } pLine = lp[i+row]; dw_draw_text(0, hpm, 0, y, pLine+col); diff -r 8a5131cbbe93 -r 86286f528adf gtk/dw.c --- a/gtk/dw.c Tue Nov 15 02:29:56 2022 +0000 +++ b/gtk/dw.c Tue Nov 15 03:50:00 2022 +0000 @@ -9917,7 +9917,7 @@ { memcpy(newarray, array, sizeof(struct _dw_seminfo)*z); if(z!=(connectcount-1)) - memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(z-connectcount-1)); + memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1))); } connectcount--; diff -r 8a5131cbbe93 -r 86286f528adf gtk3/dw.c --- a/gtk3/dw.c Tue Nov 15 02:29:56 2022 +0000 +++ b/gtk3/dw.c Tue Nov 15 03:50:00 2022 +0000 @@ -8605,15 +8605,15 @@ return DW_ERROR_NONE; } -struct _seminfo { +struct _dw_seminfo { int fd; int waiting; }; -static void _handle_sem(int *tmpsock) +static void _dw_handle_sem(int *tmpsock) { fd_set rd; - struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); + struct _dw_seminfo *array = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)); int listenfd = tmpsock[0]; int bytesread, connectcount = 1, maxfd, z, posted = 0; char command; @@ -8660,14 +8660,14 @@ if(FD_ISSET(listenfd, &rd)) { - struct _seminfo *newarray; + struct _dw_seminfo *newarray; int newfd = accept(listenfd, 0, 0); if(newfd > -1) { /* Add new connections to the set */ - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1)); - memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1)); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*(connectcount)); newarray[connectcount].fd = newfd; newarray[connectcount].waiting = 0; @@ -8687,17 +8687,17 @@ { if((bytesread = read(array[z].fd, &command, 1)) < 1) { - struct _seminfo *newarray; + struct _dw_seminfo *newarray; /* Remove this connection from the set */ - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount-1)); if(!z) - memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1)); + memcpy(newarray, &array[1], sizeof(struct _dw_seminfo)*(connectcount-1)); else { - memcpy(newarray, array, sizeof(struct _seminfo)*z); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*z); if(z!=(connectcount-1)) - memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1)); + memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1))); } connectcount--; @@ -8807,7 +8807,7 @@ } /* Create a thread to handle this event semaphore */ - pthread_create(&dwthread, NULL, (void *)_handle_sem, (void *)tmpsock); + pthread_create(&dwthread, NULL, (void *)_dw_handle_sem, (void *)tmpsock); return GINT_TO_POINTER(ev); } @@ -8935,7 +8935,7 @@ int dw_named_event_close(HEV eve) { /* Finally close the domain socket, - * cleanup will continue in _handle_sem. + * cleanup will continue in _dw_handle_sem. */ close(GPOINTER_TO_INT(eve)); return DW_ERROR_NONE; diff -r 8a5131cbbe93 -r 86286f528adf gtk4/dw.c --- a/gtk4/dw.c Tue Nov 15 02:29:56 2022 +0000 +++ b/gtk4/dw.c Tue Nov 15 03:50:00 2022 +0000 @@ -7793,7 +7793,7 @@ { memcpy(newarray, array, sizeof(struct _dw_seminfo)*z); if(z!=(connectcount-1)) - memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(z-connectcount-1)); + memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1))); } connectcount--; diff -r 8a5131cbbe93 -r 86286f528adf ios/dw.m --- a/ios/dw.m Tue Nov 15 02:29:56 2022 +0000 +++ b/ios/dw.m Tue Nov 15 03:50:00 2022 +0000 @@ -11243,7 +11243,7 @@ return DW_ERROR_NONE; } -struct _seminfo { +struct _dw_seminfo { int fd; int waiting; }; @@ -11251,7 +11251,7 @@ static void _dw_handle_sem(int *tmpsock) { fd_set rd; - struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); + struct _dw_seminfo *array = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)); int listenfd = tmpsock[0]; int bytesread, connectcount = 1, maxfd, z, posted = 0; char command; @@ -11297,14 +11297,14 @@ if(FD_ISSET(listenfd, &rd)) { - struct _seminfo *newarray; + struct _dw_seminfo *newarray; int newfd = accept(listenfd, 0, 0); if(newfd > -1) { /* Add new connections to the set */ - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1)); - memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1)); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*(connectcount)); newarray[connectcount].fd = newfd; newarray[connectcount].waiting = 0; @@ -11324,19 +11324,19 @@ { if((bytesread = (int)read(array[z].fd, &command, 1)) < 1) { - struct _seminfo *newarray = NULL; + struct _dw_seminfo *newarray = NULL; /* Remove this connection from the set */ if(connectcount > 1) { - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount-1)); if(!z) - memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1)); + memcpy(newarray, &array[1], sizeof(struct _dw_seminfo)*(connectcount-1)); else { - memcpy(newarray, array, sizeof(struct _seminfo)*z); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*z); if(z!=(connectcount-1)) - memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1)); + memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1))); } } connectcount--; diff -r 8a5131cbbe93 -r 86286f528adf mac/dw.m --- a/mac/dw.m Tue Nov 15 02:29:56 2022 +0000 +++ b/mac/dw.m Tue Nov 15 03:50:00 2022 +0000 @@ -12193,7 +12193,7 @@ return DW_ERROR_NONE; } -struct _seminfo { +struct _dw_seminfo { int fd; int waiting; }; @@ -12201,7 +12201,7 @@ static void _dw_handle_sem(int *tmpsock) { fd_set rd; - struct _seminfo *array = (struct _seminfo *)malloc(sizeof(struct _seminfo)); + struct _dw_seminfo *array = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)); int listenfd = tmpsock[0]; int bytesread, connectcount = 1, maxfd, z, posted = 0; char command; @@ -12247,14 +12247,14 @@ if(FD_ISSET(listenfd, &rd)) { - struct _seminfo *newarray; + struct _dw_seminfo *newarray; int newfd = accept(listenfd, 0, 0); if(newfd > -1) { /* Add new connections to the set */ - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount+1)); - memcpy(newarray, array, sizeof(struct _seminfo)*(connectcount)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount+1)); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*(connectcount)); newarray[connectcount].fd = newfd; newarray[connectcount].waiting = 0; @@ -12274,19 +12274,19 @@ { if((bytesread = (int)read(array[z].fd, &command, 1)) < 1) { - struct _seminfo *newarray = NULL; + struct _dw_seminfo *newarray = NULL; /* Remove this connection from the set */ if(connectcount > 1) { - newarray = (struct _seminfo *)malloc(sizeof(struct _seminfo)*(connectcount-1)); + newarray = (struct _dw_seminfo *)malloc(sizeof(struct _dw_seminfo)*(connectcount-1)); if(!z) - memcpy(newarray, &array[1], sizeof(struct _seminfo)*(connectcount-1)); + memcpy(newarray, &array[1], sizeof(struct _dw_seminfo)*(connectcount-1)); else { - memcpy(newarray, array, sizeof(struct _seminfo)*z); + memcpy(newarray, array, sizeof(struct _dw_seminfo)*z); if(z!=(connectcount-1)) - memcpy(&newarray[z], &array[z+1], sizeof(struct _seminfo)*(z-connectcount-1)); + memcpy(&newarray[z], &array[z+1], sizeof(struct _dw_seminfo)*(connectcount-(z+1))); } } connectcount--;