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

            Bug ID: 123024
           Summary: -Wstringop-overread: bogus diagnostic about strncat(3)
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

In file included from /usr/include/string.h:548,
                 from /usr/include/x86_64-linux-gnu/bsd/string.h:28,
                 from logoutd.c:16:
In function ‘strncat’,
    inlined from ‘main’ at logoutd.c:210:4:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:138:10: error:
‘__builtin___strncat_chk’ argument 2 declared attribute ‘nonstring’
[-Werror=stringop-overread]
  138 |   return __builtin___strncat_chk (__dest, __src, __len,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  139 |                                   __glibc_objsize (__dest));
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~


which is triggered by the following code:

                        char  tty_name[sizeof(ut->ut_line) + 6];  // /dev/ +
NUL
...
                        if (strncmp(ut->ut_line, "/dev/", 5) != 0)
                                strcpy(tty_name, "/dev/");
                        else
                                strcpy(tty_name, "");

                        strncat_a(tty_name, ut->ut_line);

where strncat_a() is defined as

    #define strncat_a(dst, src)  strncat(dst, src, countof(src))


This is a totally valid strncat(3) call.  Please move this out of
-Wstringop-overflow into something new such as -Wstrncat.

Reply via email to