Odd warning: array subscript is above array bounds

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

 



Hello,

Consider the following testcase:

extern int n, xyz, array[8];
void foo(void)
{
	int i, j, Dupe;

	for (i = 0; i < n; i ++) {
		Dupe = 0;
		for (j = 0; j < i; j ++)
			if (array[j] == array[i])
				Dupe = 1;
		if (array[i] && !Dupe)
			xyz = 42;
	}
}

$ gcc-7.2 -Wall -O3 -S testcase.c
testcase.c: In function 'foo':
testcase.c:11:12: warning: array subscript is above array bounds [-Warray-bounds]
   if (array[i] && !Dupe)
       ~~~~~^~~

$ gcc-6.3 -Wall -O3 -S testcase.c
/* NO WARNING */

I'm not sure how/why GCC concludes out-of-bounds access?
Could it be a false positive?

Regards.



[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