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



EXPR_WILD

Expression uses wild pointer

This error is generated whenever a program operates on a memory region that is unknown to Insure++. This can come about in two 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 local variable but contains an error at line 8 - the address operator (&) has been omitted.


	1:	/*
	2:	 * File: expwld1.c
	3:	 */
	4:	main()
	5:	{
	6:		int i = 123, j=345, *a;
	7:
	8:		a = i;
	9:		if(a > &i) bug
	10:			a = &j;
	11:		return (0);
	12:	}

Diagnosis (at runtime)


	[expwld1.c:9] **EXPR_WILD**
1.	>> 		if(a > &i)
	
2.		Expression uses wild pointer: a > &i
	
3.		Pointer : 0x0000007b
	
		Stack trace where the error occurred:
4.				main() expwld1.c,


  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 wild 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 in line 8 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 finally attempting to use it.


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

Note that this code will not generate compile time errors.

Diagnosis (at runtime)


	[expwld2.c:15] **EXPR_WILD**
1.	>> 		if(u.ptr > &j)
	
2.		Expression uses wild pointer: u.ptr > &j
	
3.		Pointer : 0x0000007b
	
		Stack trace where the error occurred:
4.				main() expwld2.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 prior to the error and single-step it through the code leading up to the error.

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


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