https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78913
Bug ID: 78913 Summary: Probably wrong -Wformat-length= error message Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: marxin at gcc dot gnu.org CC: msebor at gcc dot gnu.org Target Milestone: --- Isolated from fcoe-utils: $ cat /tmp/sprintf.c struct buffer { char path[512]; }; int main(int argc, char **argv) { static struct buffer a; struct buffer out; __builtin_strcpy (a.path, "test"); __builtin_snprintf (out.path, sizeof (struct buffer), "%s/_\n", a.path); __builtin_printf (out.path); } $ ./xgcc -B. /tmp/sprintf.c -Wall -O2 && ./a.out 1 /tmp/sprintf.c: In function ‘main’: /tmp/sprintf.c:12:61: warning: output may be truncated before the last format character [-Wformat-length=] __builtin_snprintf (out.path, sizeof (struct buffer), "%s/_\n", a.path); ^~~ /tmp/sprintf.c:12:3: note: format output between 4 and 515 bytes into a destination of size 512 __builtin_snprintf (out.path, sizeof (struct buffer), "%s/_\n", a.path); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test/_ I guess it's bogus as considering that strlen of path would be 512 is kind of misleading. Thanks, Martin