]> granicus.if.org Git - sysstat/commitdiff
iostat.c: Fix gcc format-truncation warning
authorSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 20 Jul 2018 07:38:38 +0000 (09:38 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Fri, 20 Jul 2018 07:38:38 +0000 (09:38 +0200)
Resize buffers to avoid warnings from gcc:

iostat.c: In function ‘read_sysfs_dlist_part_stat’:
iostat.c:576:39: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size between 0 and 1023 [-Wformat-truncation=]
   snprintf(filename, MAX_PF_NAME, "%s/%s/%s", dfile, drd->d_name, S_STAT);
                                       ^~
iostat.c:576:3: note: ‘snprintf’ output between 7 and 1285 bytes into a destination of size 1024
   snprintf(filename, MAX_PF_NAME, "%s/%s/%s", dfile, drd->d_name, S_STAT);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
iostat.c

index 9fa4b549232b5ac1ed7e057bc22ccc3ef9003791..dd000b4219dfebca4640541d6e7b7353031ea864 100644 (file)
--- a/iostat.c
+++ b/iostat.c
@@ -560,10 +560,10 @@ void read_sysfs_dlist_part_stat(int curr, char *dev_name)
 {
        DIR *dir;
        struct dirent *drd;
-       char dfile[MAX_PF_NAME], filename[MAX_PF_NAME];
+       char dfile[MAX_PF_NAME], filename[MAX_PF_NAME + 512];
 
-       snprintf(dfile, MAX_PF_NAME, "%s/%s", SYSFS_BLOCK, dev_name);
-       dfile[MAX_PF_NAME - 1] = '\0';
+       snprintf(dfile, sizeof(dfile), "%s/%s", SYSFS_BLOCK, dev_name);
+       dfile[sizeof(dfile) - 1] = '\0';
 
        /* Open current device directory in /sys/block */
        if ((dir = opendir(dfile)) == NULL)
@@ -573,8 +573,8 @@ void read_sysfs_dlist_part_stat(int curr, char *dev_name)
        while ((drd = readdir(dir)) != NULL) {
                if (!strcmp(drd->d_name, ".") || !strcmp(drd->d_name, ".."))
                        continue;
-               snprintf(filename, MAX_PF_NAME, "%s/%s/%s", dfile, drd->d_name, S_STAT);
-               filename[MAX_PF_NAME - 1] = '\0';
+               snprintf(filename, sizeof(filename), "%s/%s/%s", dfile, drd->d_name, S_STAT);
+               filename[sizeof(filename) - 1] = '\0';
 
                /* Read current partition stats */
                read_sysfs_file_stat(curr, filename, drd->d_name);