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

--- Comment #3 from Alejandro Colomar <[email protected]> ---
(In reply to Andrew Pinski from comment #2)
> Can you provide a full compilable example?

I seem to be unable to trigger it with a call to strncat(3) in a small example,
but I can trigger it with a manual call to the builtin.


alx@devuan:~/tmp$ cat s-overread.c 
#include <string.h>
#include <utmp.h>

void
f(struct utmp *ut, char buf[_Countof(ut->ut_line) + 1])
{
        strcpy(buf, "");
        strncat(buf, ut->ut_line, _Countof(ut->ut_line));

        strcpy(buf, "");
        __builtin___strncat_chk(buf, ut->ut_line, _Countof(ut->ut_line),
                                _Countof(ut->ut_line) + 1);
}
alx@devuan:~/tmp$ /opt/local/gnu/gcc/maxof8/bin/gcc -S -Wstringop-overread
s-overread.c
s-overread.c: In function ‘f’:
s-overread.c:11:9: warning: ‘__builtin___strncat_chk’ argument 2 declared
attribute ‘nonstring’ [-Wstringop-overread]
   11 |         __builtin___strncat_chk(buf, ut->ut_line,
_Countof(ut->ut_line),
      |        
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   12 |                                 _Countof(ut->ut_line) + 1);
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/utmp.h:29,
                 from s-overread.c:2:
/usr/include/x86_64-linux-gnu/bits/utmp.h:62:8: note: argument ‘ut_line’
declared here
   62 |   char ut_line[UT_LINESIZE]
      |        ^~~~~~~

Reply via email to