This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/79257] spurious -Wformat-overflow=1 warning with -O2 and sanitizer
- From: "catwell-gcc at catwell dot info" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 04 Jul 2017 19:04:34 +0000
- Subject: [Bug middle-end/79257] spurious -Wformat-overflow=1 warning with -O2 and sanitizer
- Auto-submitted: auto-generated
- References: <bug-79257-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79257
Pierre Chapuis <catwell-gcc at catwell dot info> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |catwell-gcc at catwell dot info
--- Comment #5 from Pierre Chapuis <catwell-gcc at catwell dot info> ---
I think I can reproduce something similar *without* the sanitizer.
Using GCC 7.1.1, with:
#include <stdio.h>
int main () {
int i; char obuf[3];
int start = 0x00;
for (i = start; i <= 0xff; ++i) {
sprintf(obuf, "%02x", i);
}
return 0;
}
I get:
demo.c: In function ‘main’:
demo.c:6:23: warning: ‘sprintf’ may write a terminating nul past the end of the
destination [-Wformat-overflow=]
sprintf(obuf, "%02x", i);
^~~~~~
demo.c:6:9: note: ‘sprintf’ output between 3 and 4 bytes into a destination of
size 3
sprintf(obuf, "%02x", i);
^~~~~~~~~~~~~~~~~~~~~~~~
At O1 I don't get the warning.
If I set `start` to `0xfb` or `0xfc`, I get the same warning. If I set it to
`0xfe` or `0xff` I don't get a warning. If I set it to `0xfd` I get the warning
*twice*:
demo.c: In function ‘main’:
demo.c:6:23: warning: ‘sprintf’ may write a terminating nul past the end of the
destination [-Wformat-overflow=]
sprintf(obuf, "%02x", i);
^~~~~~
demo.c:6:9: note: ‘sprintf’ output between 3 and 4 bytes into a destination of
size 3
sprintf(obuf, "%02x", i);
^~~~~~~~~~~~~~~~~~~~~~~~
demo.c:6:23: warning: ‘sprintf’ may write a terminating nul past the end of the
destination [-Wformat-overflow=]
sprintf(obuf, "%02x", i);
^~~~~~
demo.c:6:9: note: ‘sprintf’ output between 3 and 4 bytes into a destination of
size 3
sprintf(obuf, "%02x", i);
^~~~~~~~~~~~~~~~~~~~~~~~