[Bug middle-end/56210] New: invalid -Warray-bounds warning
jim at meyering dot net
gcc-bugzilla@gcc.gnu.org
Tue Feb 5 00:25:00 GMT 2013
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: unassigned@gcc.gnu.org
ReportedBy: jim@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...
More information about the Gcc-bugs
mailing list