out of bound warning in non-builtin strcmp() with a fixed argument with two characters.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux