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

            Bug ID: 77671
           Summary: missing -Wformat-length warning on overflow  %s
           Product: gcc
           Version: 7.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: ---

$ cat v.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall
-Wextra -Wpedantic v.c
char d[3];

extern int sprintf (char*, const char*, ...);

void f (void) {
  sprintf (d, "%-s", "abcd");
}

void g (void) {
  sprintf (d, "%s", "abcd");
}

v.c: In function ā€˜fā€™:
v.c:6:16: warning: ā€˜%-sā€™ directive writing 4 bytes into a region of size 3
[-Wformat-length=]
   sprintf (d, "%-s", "abcd");
                ^~~   ~~~~~~
v.c:6:3: note: format output 5 bytes into a destination of size 3
   sprintf (d, "%-s", "abcd");
   ^~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to