https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88993

            Bug ID: 88993
           Summary: GCC 9 -Wformat-overflow=2 should reflect real libc
                    limits
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rjones at redhat dot com
  Target Milestone: ---

-Wformat-overflow=2 is the default when using gnulib manywarnings.m4, and
so is used by a bunch of GNU projects.  I've found with GCC 9 it is very
aggressive warning about any string it statically determine could be
longer than 4095 characters (see
https://stackoverflow.com/questions/8119914/printf-fprintf-maximum-size-according-to-c99?rq=1
for the presumed origin of that limit).

I am using a libc which does not have such a small limit (in fact, I believe
it's unlimited) and I think this warning should warn about the real
toolchain limit, not some peculiar corner of the C99 standard that vanishingly
small number of libcs are really limited by (and if they are - fix your libc).

Example below:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main (void)
{
  char s[4097];

  fgets (s, sizeof s, stdin);
  printf ("%.*s", (int) strlen (s), s);

//test.c:11:12: warning: ā€˜%.*sā€™ directive output between 0 and 4096 bytes may
exceed minimum required size of 4095 [-Wformat-overflow=]
//   11 |   printf ("%.*s", (int) strlen (s), s);
//      |            ^~~~                     ~

  printf ("%s", s);

//test.c:12:12: warning: ā€˜%sā€™ directive output between 0 and 4096 bytes may
exceed minimum required size of 4095 [-Wformat-overflow=]
//   12 |   printf ("%s", s);
//      |            ^~   ~

  exit (0);
}

Reply via email to