This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/85602] New: regression with strncat and -Wall in GCC 8


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85602

            Bug ID: 85602
           Summary: regression with strncat and -Wall in GCC 8
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at gnu dot org
  Target Milestone: ---

Created attachment 44051
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44051&action=edit
test program illustrating the regression

I ran into some problems building GNU Coreutils with gcc (GCC) 8.0.1 20180324
(Red Hat 8.0.1-0.20) and isolated it to the attached program w.c. The command
"gcc -Wall w.c" reports:

w.c: In function ‘main’:
w.c:11:35: warning: argument to ‘sizeof’ in ‘strncat’ call is the same
expression as the source; did you mean to use the size of the destination?
[-Wsizeof-pointer-memaccess]
   strncat (buf, u.ut_user, sizeof u.ut_user);

This diagnostic is quite wrong, and propagates confusion about strncat. Unlike
strncpy, strncat does not zero-fill the destination, and it is almost always
incorrect to do as GCC suggests which is to specify the size of the destination
as the third argument.

The source code is correct as-is: it is one of the few places where strncat is
the right function to use, as strncat was designed for struct utmp and similar
data structures. GCC 7 does not warn about this usage, and GCC 8 should not
warn either.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]