This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/79448] New: unhelpful -Wformat-truncation=2 warning
- From: "mark at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 09 Feb 2017 23:23:04 +0000
- Subject: [Bug c/79448] New: unhelpful -Wformat-truncation=2 warning
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79448
Bug ID: 79448
Summary: unhelpful -Wformat-truncation=2 warning
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: mark at gcc dot gnu.org
Target Milestone: ---
gcc (GCC) 7.0.1 20170209 (experimental)
$ cat t.c
#include <stdio.h>
char *
gettext (char *__msgid)
{
return __msgid;
}
char *
fill (char *buf, size_t len, int count)
{
if (snprintf (buf, len, "%s: %d", gettext ("count"), count) >= len)
return NULL;
return buf;
}
$ gcc -Wformat-truncation=2 -c t.c
t.c: In function ‘fill’:
t.c:12:7: warning: ‘: ’ directive output of 2 bytes causes result to exceed
‘INT_MAX’ [-Wformat-truncation=]
if (snprintf (buf, len, "%s: %d", gettext ("count"), count) >= len)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~