]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
misc: fix gcc-7 snprintf warnings -Wformat-truncation
authorRuediger Meier <ruediger.meier@ga-group.nl>
Sun, 11 Jun 2017 21:18:21 +0000 (23:18 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Jun 2017 09:48:22 +0000 (11:48 +0200)
../lib/loopdev.c: In function 'loopcxt_next_from_sysfs':
../lib/loopdev.c:545:32: warning: '/loop/backing_file' directive output may be truncated writing 18 bytes into a region of size between 1 and 256 [-Wformat-truncation=]
   snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name);
                                ^~~~~~~~~~~~~~~~~~~~~~
../lib/loopdev.c:545:3: note: 'snprintf' output between 19 and 274 bytes into a destination of size 256
   snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../lib/sysfs.c: In function 'sysfs_is_partition_dirent':
../lib/sysfs.c:343:31: warning: '/start' directive output may be truncated writing 6 bytes into a region of size between 1 and 256 [-Wformat-truncation=]
  snprintf(path, sizeof(path), "%s/start", d->d_name);
                               ^~~~~~~~~~
../lib/sysfs.c:343:2: note: 'snprintf' output between 7 and 262 bytes into a destination of size 256
  snprintf(path, sizeof(path), "%s/start", d->d_name);
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/sysfs.c: In function 'sysfs_partno_to_devno':
../lib/sysfs.c:372:32: warning: '/partition' directive output may be truncated writing 10 bytes into a region of size between 1 and 256 [-Wformat-truncation=]
   snprintf(path, sizeof(path), "%s/partition", d->d_name);
                                ^~~~~~~~~~~~~~
../lib/sysfs.c:372:3: note: 'snprintf' output between 11 and 266 bytes into a destination of size 256
   snprintf(path, sizeof(path), "%s/partition", d->d_name);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../lib/sysfs.c:377:33: warning: '/dev' directive output may be truncated writing 4 bytes into a region of size between 1 and 256 [-Wformat-truncation=]
    snprintf(path, sizeof(path), "%s/dev", d->d_name);
                                 ^~~~~~~~
../lib/sysfs.c:377:4: note: 'snprintf' output between 5 and 260 bytes into a destination of size 256
    snprintf(path, sizeof(path), "%s/dev", d->d_name);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
lib/loopdev.c
lib/sysfs.c

index 00066823c7d6bdac8e4b71e808737506a9ccafc9..8c653a361daa168b0134918d2dedc6c81627a5b1 100644 (file)
@@ -532,7 +532,7 @@ static int loopcxt_next_from_sysfs(struct loopdev_cxt *lc)
        fd = dirfd(iter->sysblock);
 
        while ((d = readdir(iter->sysblock))) {
-               char name[256];
+               char name[NAME_MAX + 18 + 1];
                struct stat st;
 
                DBG(ITER, ul_debugobj(iter, "check %s", d->d_name));
index cc290faac49e893a228c3b909200c6f32cdd30c5..68b43aaa33eb4a356819279d4ac3245d44433e40 100644 (file)
@@ -307,7 +307,7 @@ static struct dirent *xreaddir(DIR *dp)
 
 int sysfs_is_partition_dirent(DIR *dir, struct dirent *d, const char *parent_name)
 {
-       char path[256];
+       char path[NAME_MAX + 6 + 1];
 
 #ifdef _DIRENT_HAVE_D_TYPE
        if (d->d_type != DT_DIR &&
@@ -356,7 +356,7 @@ dev_t sysfs_partno_to_devno(struct sysfs_cxt *cxt, int partno)
 {
        DIR *dir;
        struct dirent *d;
-       char path[256];
+       char path[NAME_MAX + 10 + 1];
        dev_t devno = 0;
 
        dir = sysfs_opendir(cxt, NULL);