Fix the following warning when running make distcheck
../../../../src/tools/cgsnapshot.c: In function ‘is_ctlr_on_list’:
../../../../src/tools/cgsnapshot.c:532:57: warning: ‘%s’ directive output may be truncated writing up to 409599 bytes into a region of size 4096 [-Wformat-truncation=]
532 | snprintf(controllers[i], FILENAME_MAX, "%s", tmp_controllers[i]);
| ^~
Suggested-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
/* Lets reset the controllers to intersection of controller ∩ wanted_conts */
for (i = 0; tmp_controllers[i][0] != '\0'; i++) {
- snprintf(controllers[i], FILENAME_MAX, "%s", tmp_controllers[i]);
+ /*
+ * gcc complains about truncation when using snprintf() and
+ * and coverity complains about truncation when using strncpy().
+ * Avoid both these warnings by directly invoking memcpy()
+ */
+ memcpy(controllers[i], tmp_controllers[i], sizeof(controllers[i]));
ret = 1;
}
(controllers[i])[0] = '\0';