This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/57452] FAIL: c-c++-common/cilk-plus/AN/if_test.c
- From: "hjl.tools at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 29 May 2013 16:25:33 +0000
- Subject: [Bug c/57452] FAIL: c-c++-common/cilk-plus/AN/if_test.c
- Auto-submitted: auto-generated
- References: <bug-57452-4 at http dot gcc dot gnu dot org/bugzilla/>
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?