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



             Bug #: 56210

           Summary: invalid -Warray-bounds warning

    Classification: Unclassified

           Product: gcc

           Version: 4.8.0

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: middle-end

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: j...@meyering.net





The following code evokes what looks like an invalid warning with

-Warray-bounds.

It is independent of char signedness (same with -funsigned-char or with

-fsigned-char), so should be different from bug#35903.



$ cat k.c

#include <string.h>

#include <stdio.h>



void

f (void)

{

    char *p = ";";

    while (*p) {

        static char key[] = "abc";

        if (strncmp(p, key, 3) == 0) {

            p += 3;

            printf("%s\n", p);

            return;

        }

        if ((p = strchr(p, ';')) == NULL)

            return;

        p++;

    }

}

$ gcc -save-temps -O2 -Wall -c k.c

k.c: In function 'f':

k.c:12:19: warning: array subscript is above array bounds [-Warray-bounds]

             printf("%s\n", p);

                   ^

$ gcc -v

Using built-in specs.

COLLECT_GCC=/p/bin/gcc

COLLECT_LTO_WRAPPER=/p/p/gcc-2013-01-16.09h15/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper

Target: x86_64-unknown-linux-gnu

Configured with: /h/j/w/co/gcc/configure --prefix=/p/p/gcc-2013-01-16.09h15

--enable-languages='c++ go'

Thread model: posix

gcc version 4.8.0 20130116 (experimental) (GCC)





Attaching the .i file momentarily...

Reply via email to