This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/79448] New: unhelpful -Wformat-truncation=2 warning


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]