]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix GCC string truncation warnings
authorWolfgang Stöggl <c72578@yahoo.de>
Fri, 12 Apr 2019 14:59:36 +0000 (16:59 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Sat, 13 Apr 2019 15:06:36 +0000 (17:06 +0200)
- Fixes the following GCC compiler warnings:
  rrd_fetch.c:338:9: warning: 'strncpy' output may be truncated copying
  19 bytes from a string of length 19 [-Wstringop-truncation]
    strncpy((*ds_namv)[i], rrd.ds_def[i].ds_nam, DS_NAM_SIZE - 1);
  rrd_tune.c:284:13: warning: 'strncpy' output may be truncated copying
  19 bytes from a string of length 19 [-Wstringop-truncation]
    strncpy(rrd.ds_def[ds].ds_nam, ds_new, DS_NAM_SIZE - 1);
  rrd_graph.c:2282:17: warning: 'strncpy' output may be truncated
    copying 204 bytes from a string of length 204
    [-Wstringop-truncation] strncpy(im->gdes[i].legend, saved_legend,
    sizeof im->gdes[0].legend - 1);

src/rrd_fetch.c
src/rrd_graph.c
src/rrd_tune.c

index 43cf2ba1892ee1b5ee186eea586b6ea722d66b54..55da4a32c1bef42696fd48c27a76a16c1be9ea5a 100644 (file)
@@ -335,7 +335,7 @@ int rrd_fetch_fn(
             rrd_set_error("malloc fetch ds_namv entry");
             goto err_free_ds_namv;
         }
-        strncpy((*ds_namv)[i], rrd.ds_def[i].ds_nam, DS_NAM_SIZE - 1);
+        strncpy((*ds_namv)[i], rrd.ds_def[i].ds_nam, DS_NAM_SIZE);
         (*ds_namv)[i][DS_NAM_SIZE - 1] = '\0';
 
     }
index 2bf53eca87e4fdd9160b2fb411a3d0343b80b2d8..2b3bc445cea5a3a4c9ef0f8e7fddc01b045efb9c 100644 (file)
@@ -2279,7 +2279,7 @@ int leg_place(
             }
 
             if(calc_width){
-                strncpy(im->gdes[i].legend, saved_legend, sizeof im->gdes[0].legend - 1);
+                strncpy(im->gdes[i].legend, saved_legend, sizeof im->gdes[0].legend);
                 im->gdes[i].legend[sizeof im->gdes[0].legend - 1] = '\0';
             }
         }
index 39de4dcac75e614bfafb672753c5811bb3134b70..559b94c27f7e89189df132c03579ec7dbf361786 100644 (file)
@@ -281,7 +281,7 @@ int rrd_tune(
             if ((ds = ds_match(&rrd, ds_nam)) == -1) {
                goto done;
             }
-            strncpy(rrd.ds_def[ds].ds_nam, ds_new, DS_NAM_SIZE - 1);
+            strncpy(rrd.ds_def[ds].ds_nam, ds_new, DS_NAM_SIZE);
             rrd.ds_def[ds].ds_nam[DS_NAM_SIZE - 1] = '\0';
             break;
         case 'p':