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 tree-optimization/83733] -Wformat-overflow false positive for %d on bounded integer when inlining


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed als on on trunk (GCC 8) with the reduced test case below.  As the
warning indicates, the range gets reset to that of short.

$ cat pr83733.c && gcc -O2 -S -Wall pr83733.c
struct S { char a[9], b; };

static void f (struct S *p, int i)
{
  if (i < 0 || i >= 32)
    return;

  __builtin_sprintf (p->a, "CMPRT%02d", i);
}

void g (struct S *p, int i, short j)
{
  if (i < 0 || i >= 32)
    return;

  if (i == 0)
    i = j;

  f (p, i);
}
pr83733.c: In function ‘g’:
pr83733.c:8:34: warning: ‘%02d’ directive writing between 2 and 6 bytes into a
region of size 4 [-Wformat-overflow=]
   __builtin_sprintf (p->a, "CMPRT%02d", i);
                                  ^~~~
pr83733.c:8:28: note: directive argument in the range [-32768, 32767]
   __builtin_sprintf (p->a, "CMPRT%02d", i);
                            ^~~~~~~~~~~
pr83733.c:8:3: note: ‘__builtin_sprintf’ output between 8 and 12 bytes into a
destination of size 9
   __builtin_sprintf (p->a, "CMPRT%02d", i);
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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