[Bug c/89161] Bogus -Wformat-overflow warning with value range known
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri May 1 17:50:16 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89161
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail|9.0 |10.0, 9.2.0
Last reconfirmed|2019-02-02 00:00:00 |2020-5-1
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirming with GCC 10 with slightly different output:
pr89161.c:7: sprintf: objsize = 3, fmtstr = ".%1u"
Directive 1 at offset 0: ".", length = 1
Result: 1, 1, 1, 1 (1, 1, 1, 1)
Directive 2 at offset 1: "%1u"
pr89161.c: In function ‘main’:
pr89161.c:7:24: warning: ‘%1u’ directive writing between 1 and 6 bytes into a
region of size 2 [-Wformat-overflow=]
7 | sprintf(buf, ".%1u", (10 * a[0]) / a[1]);
| ^~~
pr89161.c:7:22: note: directive argument in the range [0, 327675]
7 | sprintf(buf, ".%1u", (10 * a[0]) / a[1]);
| ^~~~~~
Result: 1, 6, 6, 6 (2, 7, 7, 7)
Directive 3 at offset 4: "", length = 1
pr89161.c:7:9: note: ‘sprintf’ output between 3 and 8 bytes into a destination
of size 3
7 | sprintf(buf, ".%1u", (10 * a[0]) / a[1]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Gcc-bugs
mailing list