git: sbin/hammer2: Silence -Wformat-truncation= warning on Linux (gcc 7.3)

Tomohiro Kusumi tkusumi at crater.dragonflybsd.org
Sat Jan 12 21:51:17 PST 2019


commit c5122b6a551adca512e12cc697805fd194e186fa
Author: Tomohiro Kusumi <kusumi.tomohiro at gmail.com>
Date:   Sun Jan 13 14:40:19 2019 -0800

    sbin/hammer2: Silence -Wformat-truncation= warning on Linux (gcc 7.3)
    
    filename[HAMMER2_INODE_MAXNAME] may not be sufficient if
    snprintf source pfs.name string is large enough. To silence
    the warning, filename[] needs another 16 bytes.
    
    This doesn't make difference on runtime, because bytes beyond
    sizeof(pfs.name) won't be used even if strlen(pfs.name) is
    large enough that filename[] contents exceeds sizeof(pfs.name).
    
    (i.e. end result of pfs.name may be incomplete with or without
    this commit)
    
    --
    cmd_snapshot.c: In function 'cmd_pfs_snapshot':
    cmd_snapshot.c:84:9: warning: '%04d' directive output may be truncated writing between 4 and 11 bytes into a region of size between 0 and 255 [-Wformat-truncation=]
         "%s.%04d%02d%02d.%02d%02d%02d",
             ^~~~
    cmd_snapshot.c:83:3: note: 'snprintf' output between 17 and 324 bytes into a destination of size 256
       snprintf(filename, sizeof(filename),
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         "%s.%04d%02d%02d.%02d%02d%02d",
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         pfs.name,
         ~~~~~~~~~
         tp->tm_year + 1900,
         ~~~~~~~~~~~~~~~~~~~
         tp->tm_mon + 1,
         ~~~~~~~~~~~~~~~
         tp->tm_mday,
         ~~~~~~~~~~~~
         tp->tm_hour,
         ~~~~~~~~~~~~
         tp->tm_min,
         ~~~~~~~~~~~
         tp->tm_sec);
         ~~~~~~~~~~~

Summary of changes:
 sbin/hammer2/cmd_snapshot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/c5122b6a551adca512e12cc697805fd194e186fa


-- 
DragonFly BSD source repository


More information about the Commits mailing list