write_mongodb: fix build warning
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sun, 2 Jul 2017 20:12:18 +0000 (22:12 +0200)
committerRuben Kerkhof <ruben@rubenkerkhof.com>
Sun, 2 Jul 2017 20:12:18 +0000 (22:12 +0200)
  CC       src/write_mongodb_la-write_mongodb.lo
src/write_mongodb.c: In function ‘wm_config’:
src/write_mongodb.c:371:55: warning: ‘%s’ directive output may be truncated writing up to 127 bytes into a region of size 114 [-Wformat-truncation=]
     snprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);
                                                       ^~
src/write_mongodb.c:371:5: note: ‘snprintf’ output between 15 and 142 bytes into a destination of size 128
     snprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/write_mongodb.c

index 2cb4537..37e3409 100644 (file)
@@ -366,7 +366,7 @@ static int wm_config_node(oconfig_item_t *ci) /* {{{ */
   }
 
   if (status == 0) {
-    char cb_name[DATA_MAX_NAME_LEN];
+    char cb_name[sizeof("write_mongodb/") + DATA_MAX_NAME_LEN];
 
     snprintf(cb_name, sizeof(cb_name), "write_mongodb/%s", node->name);