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



PARM_WILD

Array parameter is wild

This error is generated whenever a parameter is declared as an array but the actual value passed when the function is called points to no known memory block.

This can come about in several ways:

  • Errors in user code that result in pointers that do not 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 pass the address of a local variable to the routine foo but contains an error at line 14 - the address operator (&) has been omitted.

	1:	/*
	2:	 * File: parmwld1.c
	3:	 */
	4:	void foo(a)
	5:		int a[];
	6:	{ bug
	7:		return;
	8:	}
	9:
	10:	main()
	11:	{
	12:		int i = 123, *a;
	13:
	14:		a = i;
	15:		foo(a);
	16:		return (0);
	17:	}

Diagnosis (at runtime)

	[parmwld1.c:6] **PARM_WILD**
1.	>> {
	
2.		Array parameter is wild: a
	
3.		Pointer : 0x0000007b
		
			Stack trace where the error occurred:
4.					 foo() parmwld1.c, 6
					main() parmwld1.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.

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 finally passing it to a function.

	1:	/*
	2:	 * File: parmwld2.c
	3:	 */
	4:	union {
	5:		int *ptr;
	6:		int ival;
	7:	} u;
	8:
	9:	void foo(a)
	10:		int a[];
	11:	{ bug
	12:		return;
	13:	}
	14:
	15:	main()
	16:	{
	17:		int i = 123;
	18:
	19:		u.ptr = (int *) &i;
	20:		u.ival = i;
	21:		foo(u.ptr);
	22:		return (0);
	23:	}

Note that this code will not generate compile time errors.

Diagnosis (at runtime)

	[parmwld2.c:11] **PARM_WILD**
1.	>> {

2.		Array parameter is wild: a

3.		Pointer : 0x0000007b

			Stack trace where the error occurred:
4.					 foo() parmwld2.c, 11
					main() parmwld2.c, 21
  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

This problem is 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 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".


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