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 - READ_WILD



READ_WILD

Reading wild pointer

This problem occurs when an attempt is made to dereference a pointer whose value is invalid or which Insure++ did not see allocated.

This can come about in several ways:

  • Errors in user code that result in pointers that don't point at any known memory block.
  • Compiling only some of the files that make up an application. This can result in Insure++ not knowing enough about memory usage to distinguish correct and erroneous behavior.
Bend This discussion centers on the first type of problem described here. A detailed discussion of the second topic, including samples of its generation and repair can be found in "Interfaces".

Problem #1

The following code attempts to use the address of a variable but contains an error at line 8 - the address operator (&) has been omitted.

	1:	/*
	2:	 * File: readwld1.c
	3:	 */
	4:	main()
	5:	{
	6:		int *a, i = 123, b;
	7:
	8:		a = i;
	9:		b = *a; bug
	10:		return (0);
	11:	}

Diagnosis (at runtime)

	[readwld1.c:9] **READ_WILD**
1.	>> 		b = *a;
	
2.		Reading wild pointer: a
	
3.		Pointer : 0x0000007b

		Stack trace where the error occurred:
4.			main() readwld1.c, 9

  1. Source line at which the problem was detected.
  2. Description of the problem and the name of the parameter that is in error.
  3. Value of the bad pointer.
  4. Stack trace showing the function call sequence leading to the error.

Note that most compilers will generate warning messages for this error since the assignment uses incompatible types.

Problem #2

A more insidious version of the same problem can occur when using union types. The following code first assigns the pointer element of a union but then overwrites it with another element before using it.

	1:	/*
	2:	 * File: readwld2.c
	3:	 */
	4:	union {
	5:		int *ptr;
	6:		int ival;
	7:	} u;
	8:
	9:	main()
	10:	{
	11:		int b, i = 123;
	12:
	13:		u.ptr = &i;
	14:		u.ival = i;
	15:		b = *u.ptr; bug
	16:		return (0);
	17:	}

Note that this code will not generate compile time errors.

Diagnosis (at runtime)

	[readwld2.c:15] **READ_WILD**
1.	>> 		b = *u.ptr;
	
2.		Reading wild pointer: u.ptr
	
3.		Pointer : 0x0000007b
	
		Stack trace where error occurred:
4.				main() readwld2.c, 15

  1. Source line at which the problem was detected.
  2. Description of the problem and the name of the parameter that is in error.
  3. Value of the bad pointer.
  4. Stack trace showing the function call sequence leading to the error.

Repair

The simpler types of problem are most conveniently tracked in a debugger by stopping the program at the indicated source line. You should then examine the illegal value and attempt to see where it was generated. Alternatively you can stop the program at some point shortly before the error and single-step through the code leading up to the problem.

Note that wild pointers can also be generated when Insure++ has only partial information about your program's structure. This issue is discussed extensively in "Interfaces".


< READ_UNINIT_PTR > RETURN_DANGLING
Tools to debug c++ and java
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft