This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/81401] False positive sprintf warning at O2 (-Wformat-overflow)
- From: "joerg dot richter at pdv-fs dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 Aug 2017 10:34:39 +0000
- Subject: [Bug tree-optimization/81401] False positive sprintf warning at O2 (-Wformat-overflow)
- Auto-submitted: auto-generated
- References: <bug-81401-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81401
Jörg Richter <joerg.richter@pdv-fs.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |joerg.richter@pdv-fs.de
--- Comment #2 from Jörg Richter <joerg.richter@pdv-fs.de> ---
See also:
#include <stdio.h>
void foo()
{
char buf[2];
for( int i = 0; i < 10; ++i )
sprintf( buf, "%d", i );
}
t.cc: In function 'void foo()':
t.cc:2:6: warning: 'sprintf' may write a terminating nul past the end of the
destination [-Wformat-overflow=]
void foo()
^~~
t.cc:6:12: note: 'sprintf' output between 2 and 3 bytes into a destination of
size 2
sprintf( buf, "%d", i );
~~~~~~~^~~~~~~~~~~~~~~~