[Bug c/18063] Gcc doesn't check overflowed size of structure

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue May 17 16:58:00 GMT 2016


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2005-09-18 01:37:52         |2016-5-17
                 CC|                            |msebor at gcc dot gnu.org
      Known to fail|                            |3.4.2, 5.3.0, 6.1.0, 7.0

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
Reconfirmed with today's trunk (7.0), 6.1.0, and all prior supported versions. 
It seems that it shouldn't be too hard to diagnose either the definition of the
struct or the sizeof expression.

$ cat uu.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -Wall
-Wextra -Wpedantic -m32 uu.c && ./a.out
struct a {
    char x[0x7fffffff];
    char b[0x7fffffff];
    char c[3];
};

int main()
{
  __builtin_printf ("%zu\n", sizeof (struct a));
  _Static_assert (sizeof (struct a) > sizeof ((struct a*)0)->x, "");
}
uu.c: In function ‘main’:
uu.c:10:37: warning: expression in static assertion is not an integer constant
expression [-Wpedantic]
   _Static_assert (sizeof (struct a) > sizeof ((struct a*)0)->x, "");
                   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
uu.c:10:3: error: static assertion failed: ""
   _Static_assert (sizeof (struct a) > sizeof ((struct a*)0)->x, "");
   ^~~~~~~~~~~~~~


More information about the Gcc-bugs mailing list