Search

ParaSoft

HOME
PRODUCTS
SUPPORT
ABOUT
WHAT'S NEW
EVENTS


Insure++

Quick facts

Add-on Modules:
   -INUSE
   -TCA

Comparisons

Technical Papers

Support & Manuals

FAQs

Recent Reviews

User Testimonials

Press Releases


Insure tool to debug c++





Insure++ Reference - WRITE_BAD_INDEX



WRITE_BAD_INDEX

Writing array out of range

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.

Problem

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; bug
	10:		return (0);
	11:	}

Diagnosis (at runtime)

	[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!!**
  1. Source line at which the problem was detected.
  2. Description of the problem and the expression that is in error.
  3. Illegal index value used.
  4. Valid index range for this array.
  5. Stack trace showing the function call sequence leading to the error.
  6. Informational message indicating that a serious error has occurred which may cause the program to crash.

Repair

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
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft