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

            Bug ID: 92815
           Summary: spurious -Wstringop-overflow writing into a flexible
                    array of an extern struct
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Diagnosing the strcpy call below isn't justified because the flexible array
into which it writes is a member of an extern object that could be initialized
to be large enough to fit the string (e.g., as shown in the comment).

$ cat t.c && gcc -O2 -S -Wall -Wno-array-bounds t.c
extern struct S s /* = { 5, { 1, 2, 3, 4, 5 } } */;

void g (void)
{
  __builtin_strcpy (s.ax, "123");   // bogus warning
}
t.c: In function ‘g’:
t.c:7:3: warning: ‘__builtin_memcpy’ writing 4 bytes into a region of size 0
overflows the destination [-Wstringop-overflow=]
    7 |   __builtin_strcpy (s.ax, "123");   // bogus warning
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to