This is the mail archive of the gcc-help@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]

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


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