fsx: fix strncpy usage error
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 11 Nov 2020 00:44:43 +0000 (16:44 -0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 15 Nov 2020 06:46:13 +0000 (14:46 +0800)
commit4f8a21fa8d3241db5a97c7f07b676c5c804c20ad
treef3dfcd5589d2afff05e607f4ec6a482d9fbd96ed
parentbd3353b0d4d966c2da33d8f5147927092c650c2e
fsx: fix strncpy usage error

We shouldn't feed sizeof() to strncpy as the string length.  Just use
snprintf, which at least doesn't have the zero termination problems.

In file included from /usr/include/string.h:495,
                 from ../src/global.h:73,
                 from fsx.c:16:
In function 'strncpy',
    inlined from 'main' at fsx.c:2944:5:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning:
'__builtin_strncpy' specified bound 4096 equals destination size
[-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'strncpy',
    inlined from 'main' at fsx.c:2914:4:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10: warning:
'__builtin_strncpy' specified bound 1024 equals destination size
[-Wstringop-truncation]
  106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
ltp/fsx.c