]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Fix warning strncpy bound equals destination size
authorWolfgang Stöggl <c72578@yahoo.de>
Fri, 14 Dec 2018 11:11:05 +0000 (12:11 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Fri, 14 Dec 2018 12:38:24 +0000 (13:38 +0100)
- Reduce num from 5 to 4 in strncpy and add null terminator.
  Remark: Version strings consist of 4 chars, e.g. RRD_VERSION5 "0005"

- Fixes the following GCC 8 warnings:
  rrd_create.c:960:9: warning:
    ‘strncpy’ specified bound 5 equals destination size
    [-Wstringop-truncation]
    strncpy(rrd.stat_head->version, require_version, 5);

  rrd_modify.c:1218:9: warning:
    ‘strncpy’ specified bound 5 equals destination size
    [-Wstringop-truncation]
    strncpy(out->stat_head->version, require_version, 5);

src/rrd_create.c
src/rrd_modify.c

index 9453cbcf6814cb328c9a47b86abcb8f2e0e03d9b..d61b20d03d96aae72d2716afba4d435818e68d93 100644 (file)
@@ -957,7 +957,8 @@ int rrd_create_r2(
     // parsing went well. ONLY THEN are we allowed to produce
     // additional side effects.
     if (require_version != NULL) {
-        strncpy(rrd.stat_head->version, require_version, 5);
+        strncpy(rrd.stat_head->version, require_version, 4);
+        rrd.stat_head->version[4] = '\0';
     }
 
     if (rrd.stat_head->rra_cnt < 1) {
index aa34f86f64e39540e0765f84ccf2a60b1e800d12..674d7db5ba1c520b45b690ac3c06d55d3ac1fad6 100644 (file)
@@ -1215,7 +1215,8 @@ static int add_rras(const rrd_t *in, rrd_t *out, const int *ds_map,
     }
 
     if (require_version != NULL && atoi(require_version) < atoi(out->stat_head->version)) {
-        strncpy(out->stat_head->version, require_version, 5);
+        strncpy(out->stat_head->version, require_version, 4);
+        out->stat_head->version[4] = '\0';
     }
 
     if (last_rra_cnt < out->stat_head->rra_cnt) {