From: Tom Hromatka Date: Sun, 5 Jan 2020 22:17:09 +0000 (-0700) Subject: api.c: Fix string truncation warning X-Git-Tag: v0.42~3^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1eb905fec003476f9fea9990ad4c9692925defcf;p=thirdparty%2Flibcgroup.git api.c: Fix string truncation warning This commit fixes this warning in api.c: api.c: In function ‘cgroup_read_value_begin’: api.c:4114:47: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=] 4114 | snprintf(stat_file, sizeof(stat_file), "%s/%s", stat_path, | ^ api.c:4114:2: note: ‘snprintf’ output 2 or more bytes (assuming 4097) into a destination of size 4096 4114 | snprintf(stat_file, sizeof(stat_file), "%s/%s", stat_path, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4115 | name); | ~~~~~ Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 30555f12..5c347fad 100644 --- a/src/api.c +++ b/src/api.c @@ -4098,7 +4098,7 @@ int cgroup_read_value_begin(const char *controller, const char *path, { int ret = 0; char *ret_c = NULL; - char stat_file[FILENAME_MAX]; + char stat_file[FILENAME_MAX + sizeof(name)]; char stat_path[FILENAME_MAX]; FILE *fp;