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)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~