]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api.c: Fix string truncation warning
authorTom Hromatka <tom.hromatka@oracle.com>
Sun, 5 Jan 2020 22:17:09 +0000 (15:17 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 8 Jan 2020 15:01:39 +0000 (08:01 -0700)
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 <tom.hromatka@oracle.com>
src/api.c

index 30555f124e74acc205740bc9f674c1f3bb26b32b..5c347fadbd83aa1dba8a1142875634862e872a2e 100644 (file)
--- 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;