Insure++ Reference - READ_BAD_INDEX
This error is generated whenever an illegal value will be used to index
an array. It is a particularly common error that can be very difficult to
detect, especially if the out-of-range elements happen to have zero values.
If this error can be detected during compilation, an error will be issued
instead of the normal runtime error.
This code attempts to access an illegal array element due to an
incorrect loop range.
1: /*
2: * File: readindx.c
3: */
4: int a[10];
5: int junk;
6: main()
7: {
8: int i, tot=0;
9:
10: for(i=1; i<=10; i++)
11: tot += a[i];
12: return (0);
13: }
[readindx.c:10] **READ_BAD_INDEX**
1. >> tot += a[i];
2. Reading array out of range: a[i]
3. Index used: 10
4. Valid range: 0 thru 9 (inclusive)
Stack trace where the error occurred:
5. main() readindx.c, 11
- Source line at which the problem was detected.
- Description of the problem and the expression that is in error.
- Illegal index value used.
- Valid index range for this array.
- Stack trace showing the function call sequence leading to the
error.
Typical sources of this error include loops with incorrect
initial or terminal conditions, as in this example, for which the
corrected code is:
main()
{
int i, tot=0, a[10];
for(i=0; i<sizeof(a)/sizeof(a[0]); i++)
tot += a[i];
return (0);
}
PARM_WILD
READ_DANGLING
|