[Bug middle-end/77720] New: -Wformat-length= wit -O3 emit warning twice with incorrect linenumbers
dimhen at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Sep 24 10:34:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77720
Bug ID: 77720
Summary: -Wformat-length= wit -O3 emit warning twice with
incorrect linenumbers
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: dimhen at gmail dot com
Target Milestone: ---
gcc version 7.0.0 20160922 (experimental) [trunk revision 240342] (GCC)
-O2 : warning for baz()
-O3 : warning for bar() and baz() but lineno twice points to baz()
$ cat x.c
int snprintf (char*, __SIZE_TYPE__, const char*, ...);
void foo(unsigned j, char *p)
{
if(j > 999)
return;
snprintf(p, 4, "%3d", j);
}
void bar(int j, char *p)
{
const unsigned k = (unsigned) j;
if(k > 999)
return;
snprintf(p, 4, "%3u", k);
}
void baz(int j, char *p)
{
if((unsigned)j > 999)
return;
snprintf(p, 4, "%3u", (unsigned)j);
}
$ gcc -Wall -c -O2 x.c
x.c: In function ‘baz’:
x.c:22:21: warning: ‘%3u’ directive output may be truncated writing between 3
and 10 bytes into a region of size 4 [-Wformat-length=]
snprintf(p, 4, "%3u", (unsigned)j);
^~~
x.c:22:20: note: directive argument in the range [0u, 4294967295u]
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~
x.c:22:5: note: format output between 4 and 11 bytes into a destination of size
4
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ gcc -Wall -c -O3 x.c
x.c: In function ‘bar’:
x.c:22:21: warning: ‘%3u’ directive output may be truncated writing between 3
and 10 bytes into a region of size 4 [-Wformat-length=]
snprintf(p, 4, "%3u", (unsigned)j);
^~~
x.c:22:20: note: directive argument in the range [0u, 4294967295u]
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~
x.c:22:5: note: format output between 4 and 11 bytes into a destination of size
4
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.c: In function ‘baz’:
x.c:22:21: warning: ‘%3u’ directive output may be truncated writing between 3
and 10 bytes into a region of size 4 [-Wformat-length=]
snprintf(p, 4, "%3u", (unsigned)j);
^~~
x.c:22:20: note: directive argument in the range [0u, 4294967295u]
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~
x.c:22:5: note: format output between 4 and 11 bytes into a destination of size
4
snprintf(p, 4, "%3u", (unsigned)j);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the Gcc-bugs
mailing list