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

gcc-4.8-20121028 array bound check


I find this array bound check too hard: 

./compiler/gcc-4.8.0-snap/bin/gcc c1.c -O3 -c -Wall

c1.c: In function ?main?:
c1.c:15:22: warning: array subscript is above array bounds
[-Warray-bounds]
?????????? if (!ab_pid[index]) 
????????????????????? ^

extern unsigned char ab_pid_count,old_rfcb_pid_count; 
extern unsigned short ab_pid[16]; 
extern int found_pid; 

int main()
{
? unsigned char pid_index = 0;
? int index; 

? for (pid_index=0; (pid_index < old_rfcb_pid_count); pid_index++)
??? {
????? for (index=0; index < ab_pid_count; index++)
??????? {
????????? if (!ab_pid[index]) 
??????????? {
????????????? found_pid = 1; 
??????????? }
??????? };
??? }

? return 0; 
}

Does this mean we have to rework the loops like 'index < ab_pid_count &&
index < 16' ? But if so, why does the warning disappear without the
outer loop or with ' unsigned short ab_pid[32]'? 

Regards. 






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