]> 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:13:51 +0000 (15:13 -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_stats_begin’:
api.c:4189:47: warning: ‘.stat’ directive output may be truncated
    writing 5 bytes into a region of size between 0 and 4095
    [-Wformat-truncation=]
    4189 |  snprintf(stat_file, sizeof(stat_file), "%s/%s.stat", stat_path,
         |                                               ^~~~~
api.c:4189:2: note: ‘snprintf’ output 7 or more bytes (assuming 4102)
    into a destination of size 4096
    4189 |  snprintf(stat_file, sizeof(stat_file), "%s/%s.stat", stat_path,
         |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    4190 |    controller);
         |    ~~~~~~~~~~~

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 0a09e6fef67fd7f9046acd40def2192965dd0df9..30555f124e74acc205740bc9f674c1f3bb26b32b 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -4173,7 +4173,7 @@ int cgroup_read_stats_begin(const char *controller, const char *path,
                                void **handle, struct cgroup_stat *cgroup_stat)
 {
        int ret = 0;
-       char stat_file[FILENAME_MAX];
+       char stat_file[FILENAME_MAX + sizeof(".stat")];
        char stat_path[FILENAME_MAX];
        FILE *fp;