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

            Bug ID: 87719
           Summary: missing warning on printf %s and unterminated 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 an unterminated array warning for calls to sprintf but not for the
equivalent calls to printf (of fprintf):

$ cat t.c && gcc -O2 -S  -Wall t.c
const char a[] = { 'a', 'b' };

void f (char *d)
{
  __builtin_sprintf (d, "%s", a);   // warning, good
}

void g (void)
{
  __builtin_printf ("%s", a);   // missing warning
}
t.c: In function ā€˜fā€™:
t.c:5:26: warning: ā€˜%sā€™ directive argument is not a nul-terminated string
[-Wformat-overflow=]
    5 |   __builtin_sprintf (d, "%s", a);   // warning, good
      |                          ^~   ~
t.c:1:12: note: referenced argument declared here
    1 | const char a[] = { 'a', 'b' };
      |            ^

Reply via email to