[Bug c/57452] FAIL: c-c++-common/cilk-plus/AN/if_test.c
hjl.tools at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed May 29 16:25:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57452
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
We have
int main2 (int argc, char **argv);
int main(int argc, char **argv)
{
int x = 0;
if (argc == 1)
{
const char *array[] = {"a.out", "10", "15"};
x = main2 (3, (char **) array);
}
else if (argc == 3)
x = main2 (argc, argv);
else
return 1;
return x;
}
int main2 (int argc, char **argv)
{
int x = 3, y, z, array[10], array2[10], TwodArray[10][10], jj,kk,ll ;
...
/* This if loop will change all the 10's to 5's */
if (array[atoi(argv[1])-10:atoi(argv[1]): atoi(argv[1])/5])
array2[:] = 5;
else
array2[:] = 10;
for (ii = atoi(argv[1])-10; ii < atoi(argv[1]) + (atoi (argv[1])-10);
ii +=atoi(argv[1])/5)
if (array[ii])
array2_check[ii] = 5;
else
array2_check[ii] = 10;
In array notation, the first element is the lower bound,
the second element is the length, which is NOT the size of
array, and the third element is the stride. The size of array
for
array[atoi(argv[1])-10:atoi(argv[1]): atoi(argv[1])/5]
is
atoi(argv[1])-10 + atoi(argv[1])/5 * (atoi(argv[1]) - 1) + 1
Since argv[1] == 10, the size of array is 10 - 10 + (10 / 5) * 9 + 1,
which is 19 and larger than int array[10]. This is invalid.
Shouldn't GCC detect it?
More information about the Gcc-bugs
mailing list