out of bound warning in non-builtin strcmp() with a fixed argument with two characters.
Alfonso Cepeda Caballos
cepeda@gmail.com
Fri Oct 16 16:58:00 GMT 2009
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
More information about the Gcc-help
mailing list