|
From: Paul P. <pa...@pa...> - 2004-09-06 22:15:50
|
Jean Pierre wrote:
> One bug I found very annoying is this one :
>
> double array[3];
> array[3] = 0;
Surely that is *not* a static array?
> In fact, so far I only found one product who can detect this and this is
> the bounds checking patch of gcc.
FWIW, Insure++ is *supposed* to find that bug (and an equivalent
one with the static array):
$ cat junk.c
int main()
{
double array[3];
static double xyz[3];
array[3] = 0;
xyz[3] = 1;
return 0;
}
$ insure gcc -g junk.c
[junk.c:5] **WRITE_BAD_INDEX**
Writing array out of range: array[3]
>> array[3] = 0;
[junk.c:6] **WRITE_BAD_INDEX**
Writing array out of range: xyz[3]
>> xyz[3] = 0;
$ ./a.out
[junk.c:5] **WRITE_BAD_INDEX**
>> array[3] = 0;
Writing array out of range: array[3]
Index used : 3
Valid range: 0 thru 2 (inclusive)
Stack trace where the error occurred:
main() junk.c, 5
**Memory corrupted. Program may crash!!**
[junk.c:6] **WRITE_BAD_INDEX**
>> xyz[3] = 0;
Writing array out of range: xyz[3]
Index used : 3
Valid range: 0 thru 2 (inclusive)
Stack trace where the error occurred:
main() junk.c, 6
Cheers,
|