[Bug middle-end/94642] New: missing -Wformat-overflow on %f with excessive precision

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Apr 17 21:43:36 GMT 2020


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

            Bug ID: 94642
           Summary: missing -Wformat-overflow on %f with excessive
                    precision
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

-Wformat-overflow diagnoses the excessive precision in the first case but it
fails to warn for the second case.

For reference:

  ...precision [...] gives the minimum number of digits to appear for the d, i,
o, u, x, and X conversions, the number of digits to appear after the
decimal-point character for a, A, e, E, f, and F conversions, ...

$ cat z.c && gcc -O2 -c -Wall z.c
char a[8];

void f (void)
{
  __builtin_sprintf (a, "%9999999999999999.9999999999999999i", 1);
}


void g (void)
{
  __builtin_sprintf (a, "%9999999999999999.9999999999999999f", 1.0);
}

z.c: In function ‘f’:
z.c:5:26: warning: ‘%9999999999999999.9999999999...’ directive writing
9999999999999999 bytes into a region of size 8 [-Wformat-overflow=]
    5 |   __builtin_sprintf (a, "%9999999999999999.9999999999999999i", 1);
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
z.c:5:3: note: ‘__builtin_sprintf’ output 10000000000000000 bytes into a
destination of size 8
    5 |   __builtin_sprintf (a, "%9999999999999999.9999999999999999i", 1);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


More information about the Gcc-bugs mailing list