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/33024] New: gcc allows negatively-sized arrays


    By using an integer variable as the size of an array to be 
    initialized on the stack, you can trick gcc into accepting
    and trying to create a negatively-sized array.  The assembly
    it generates in such a case seems to indicate it really thinks
    it has a negatively-sized array.

Environment:
System: Linux pc1 2.6.20-15-generic #2 SMP Sun Apr 15 07:36:31 UTC 2007 i686
GNU/Linux
Architecture: i686

host: i486-pc-linux-gnu
build: i486-pc-linux-gnu
target: i486-pc-linux-gnu
configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release i486-linux-gnu

How-To-Repeat:
    #include <stdio.h>

    int main(int argc, char **argv) {
        int x = -2;
        int y[x];

        printf("%d\n", sizeof(y));
    }

    This will output -8.


------- Comment #1 from sdyoung at miranda dot org  2007-08-08 16:47 -------
Fix:
    I don't know.


-- 
           Summary: gcc allows negatively-sized arrays
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sdyoung at miranda dot org
 GCC build triplet: i486-pc-linux-gnu
  GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33024


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