Insure++ Reference - WRITE_BAD_INDEX
This error is generated whenever an illegal value will be used to
index an array which is being written.
If this error can be detected during compilation, a compilation 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: writindx.c
3: */
4: main()
5: {
6: int i, a[10];
7:
8: for(i=1; i<=10; i++)
9: a[i] = 0;
10: return (0);
11: }
[writindx.c:9] **WRITE_BAD_INDEX**
1. >> a[i] = 0;
2. Writing 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() writindx.c, 9
6. **Memory corrupted. Program may crash!!**
- 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.
- Informational message indicating that a serious error has
occurred which may cause the program to crash.
This is normally a fatal error and is often introduced algorithmically.
One common source of this error is using "stretchy arrays"
without telling Insure++ about them. A "stretchy array"
is an array whose size is only determined at runtime. For an example as
well as an explanation of how to use Insure++ see
"stretchy arrays".
Other typical sources include loops with incorrect initial or terminal
conditions, as in this example, for which the corrected code is:
main()
{
int i, a[10];
for(i=; i<sizeof(a)/sizeof(a[0]); i++)
a[i] = 0;
return (0);
}
VIRTUAL_BAD
WRITE_DANGLING
|