[Bug tree-optimization/87423] New: missing warning for strcpy of an unterminated member array

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Sep 24 19:32:00 GMT 2018


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

            Bug ID: 87423
           Summary: missing warning for strcpy of an unterminated member
                    array
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC 9 issues a warning for a strcpy call with an unterminated constant array
but fails to issue the same warning when the array is a member of a const
object as shown in the test case below.  (The duplicate warning in the subject
of bug 87422).

$ cat c.c && gcc -O2 -S -Wall -Wextra -Wpedantic c.c
const char a[3] = { '1', '2', '3' };

const struct { char a[3]; } x = { { '1', '2', '3' } };

int f (void)
{
  return  __builtin_strlen (a);   // warning (good)
}

int g (void)
{
  return  __builtin_strlen (x.a);   // missing warning
}
c.c: In function ‘f’:
c.c:7:29: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
7 |   return  __builtin_strlen (a);   // warning (good)
  |                             ^
c.c:1:12: note: referenced argument declared here
1 | const char a[3] = { '1', '2', '3' };
  |            ^
c.c:7:29: warning: ‘strlen’ argument missing terminating nul
[-Wstringop-overflow=]
7 |   return  __builtin_strlen (a);   // warning (good)
  |                             ^
c.c:1:12: note: referenced argument declared here
1 | const char a[3] = { '1', '2', '3' };
  |            ^


More information about the Gcc-bugs mailing list