From 056b72c49992dd4552b3027e105e3ef52a81ca3e Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Fri, 20 Jul 2018 09:38:38 +0200 Subject: [PATCH] iostat.c: Fix gcc format-truncation warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- iostat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iostat.c b/iostat.c index 9fa4b54..dd000b4 100644 --- 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); -- 2.40.0