changeset 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 de1a0cd26691
files dwtest.c gtk/dw.c gtk3/dw.c gtk4/dw.c ios/dw.m mac/dw.m
diffstat 6 files changed, 39 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- 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);
--- 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--;
 
--- 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;
--- 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--;
 
--- 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--;
--- 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--;