]> git.ipfire.org Git - thirdparty/coreutils.git/commit
maint: avoid strncat warning on GCC
authorPádraig Brady <P@draigBrady.com>
Sat, 7 Nov 2020 21:04:12 +0000 (21:04 +0000)
committerPádraig Brady <P@draigBrady.com>
Sat, 7 Nov 2020 21:34:34 +0000 (21:34 +0000)
commit165a80f6e6f613d2443f19c87f9511ce2cf9818c
tree2cacaf6643c2d66aff1036079266d70178845ac5
parentff80b6b0a0507e24f39cc1aad09d147f5187430b
maint: avoid strncat warning on GCC

GCC 10.1.1 without optimization gives:

  error: ‘strncat’ argument 2 declared attribute ‘nonstring’
    [-Werror=stringop-overflow=]
    strncat (comment, UT_ID (utmp_ent), utmpsize);

Note the strncat man page says that:
  "src does not need to be null-terminated
   if it contains n or more bytes."
And the POSIX spec says that the second (source) parameter
is an array not a string.
So I think it's incorrect for strncat to require src be a string type.
This constraint seems to be being added to the gcc builtin strncat,
as specifiying -fno-builtin also avoids the warning.
Note specifying any optimization level also avoids the warning.

* src/who.c (make_id_equals_comment): Avoid the issue by using
stpcpy + stzncpy, instead of strcpy + strncat.
This pattern is used elsewhere in who.c
src/who.c