This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
out of bound warning in non-builtin strcmp() with a fixed argument with two characters.
- From: Alfonso Cepeda Caballos <cepeda at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 16 Oct 2009 11:43:17 +0200
- Subject: out of bound warning in non-builtin strcmp() with a fixed argument with two characters.
Hi:
I obtain a warning when compiling the following code:
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
printf("%i",strcmp(argv[0],"A")); // NO warning
printf("%i",strcmp(argv[0],"AA")); // warning: array subscript is
above array bounds
printf("%i",strcmp(argv[0],"AAA")); // NO warning
return 0;
}
with:
gcc -O3 -fno-builtin -funsigned-char -Wall test.c
test.c: In function ‘main’:
test.c:7: warning: array subscript is above array bounds
It only show the warning with this combination options (at least in
linux). If you use signed-char or the strcmp() builtin function, it
doesn't show the warning. And it only shows if the second comparision
string is two bytes length (I mean three with the \0).
Do you know why?
Thanks in advance.
--
Alfonso Cepeda