This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/77721] New: -Wformat-length not uses arg range for converted vars
- From: "dimhen at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 24 Sep 2016 10:40:33 +0000
- Subject: [Bug middle-end/77721] New: -Wformat-length not uses arg range for converted vars
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77721
Bug ID: 77721
Summary: -Wformat-length not uses arg range for converted vars
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)
no warns in foo() but warns in bar()
$ cat x.c
int snprintf (char*, __SIZE_TYPE__, const char*, ...);
void foo(unsigned j, char *p)
{
if(j > 999)
return;
snprintf(p, 4, "%3u", j);
}
void bar(int j, char *p)
{
const unsigned k = (unsigned) j;
if(k > 999)
return;
snprintf(p, 4, "%3u", k);
}
$ gcc -Wall -c -O2 x.c
x.c: In function ‘bar’:
x.c:15: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", k);
^~~
x.c:15:20: note: directive argument in the range [0u, 4294967295u]
snprintf(p, 4, "%3u", k);
^~~~~
x.c:15:5: note: format output between 4 and 11 bytes into a destination of size
4
snprintf(p, 4, "%3u", k);
^~~~~~~~~~~~~~~~~~~~~~~~