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

            Bug ID: 87756
           Summary: missing unterminated argument warning using address of
                    a constant character
           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 successfully diagnoses the unterminated array argument when it's an
actual  array but fails to do the same when the argument is the address of a
single character.

$ cat t.c && gcc -O2 -S  -Wall t.c

const char c = 'a';
const char a[] = { 'a' };

char *d, *e;

void f (void)
{
  __builtin_sprintf (d, "%s", a);    // warning (good)
  __builtin_sprintf (e, "%s", &c);   // missing warning
}

void g (void)
{
  __builtin_strcpy (d, a);    // warning (good)
  __builtin_strcpy (e, &c);   // missing warning
}
t.c: In function ‘g’:
t.c:14:3: warning: ‘strcpy’ argument missing terminating nul
[-Wstringop-overflow=]
   14 |   __builtin_strcpy (d, a);    // warning (good)
      |   ^~~~~~~~~~~~~~~~~~~~~~~
t.c:2:12: note: referenced argument declared here
    2 | const char a[] = { 'a' };
      |            ^
t.c: In function ‘f’:
t.c:8:26: warning: ‘%s’ directive argument is not a nul-terminated string
[-Wformat-overflow=]
    8 |   __builtin_sprintf (d, "%s", a);    // warning (good)
      |                          ^~   ~
t.c:2:12: note: referenced argument declared here
    2 | const char a[] = { 'a' };
      |            ^

Reply via email to