This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/77799] missing -Wformat-overflow warning on a trivial sprintf overflow with no directives
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 Aug 2017 18:18:13 +0000
- Subject: [Bug middle-end/77799] missing -Wformat-overflow warning on a trivial sprintf overflow with no directives
- Auto-submitted: auto-generated
- References: <bug-77799-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77799
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
This bug was fixed along with the related pr77671 in r248035. GCC 8.0 now
prints the following:
.c: In function ‘g’:
a.c:14:15: warning: too many arguments for format [-Wformat-extra-args]
sprintf (d, "123", 0);
^~~~~
a.c: In function ‘f’:
a.c:9:18: warning: ‘123’ directive writing 3 bytes into a region of size 2
[-Wformat-overflow=]
sprintf (d, "123");
~~^
a.c:9:3: note: ‘sprintf’ output 4 bytes into a destination of size 2
sprintf (d, "123");
^~~~~~~~~~~~~~~~~~
;; Function f (f, funcdef_no=0, decl_uid=1819, cgraph_uid=0, symbol_order=1)
f ()
{
<bb 2> [100.00%] [count: INV]:
sprintf (&d, "123"); [tail call]
return;
}
a.c: In function ‘g’:
a.c:14:18: warning: ‘123’ directive writing 3 bytes into a region of size 2
[-Wformat-overflow=]
sprintf (d, "123", 0);
~~^
a.c:14:3: note: ‘sprintf’ output 4 bytes into a destination of size 2
sprintf (d, "123", 0);
^~~~~~~~~~~~~~~~~~~~~
;; Function g (g, funcdef_no=1, decl_uid=1822, cgraph_uid=1, symbol_order=2)
g ()
{
<bb 2> [100.00%] [count: INV]:
sprintf (&d, "123", 0); [tail call]
return;
}