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_BAD_RANGE



PARM_BAD_RANGE

Array parameter exceeded range

This error is generated whenever a function parameter is declared as an array, but has more elements than the actual argument which was passed.

Problem

The following code fragment shows an array declared with one size in the main routine and then used with another in a function.

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

Diagnosis

	[parmrnge.c:6] **PARM_BAD_RANGE**
1.	>> {
	
2.		Array parameter exceeded range: a
	
3.				bbbbbb
				| 20 | 20 |
				ppppppppppp
	
4.		Parameter (p) 0xf7fffb04 thru 0xf7fffb2b (40 bytes)
		Actual block (b) 0xf7fffb04 thru 0xf7fffb17 
					(20 bytes, 5 elements)
5.				b, declared at parmrnge.c, 12

		Stack trace where the error occurred:
                		     foo() parmrnge.c, 6
6.				    main() parmrnge.c, 13

  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. Schematic showing the relative layout of the memory block which was actually passed as the argument (b) and expected parameter (p). (See Overflow diagrams)
  4. Description of the memory range occupied by the parameter, including its length.
  5. Description of the actual block of data corresponding to the argument, including its address range and size. Also includes the name of the real variable which matches the argument and the line number at which it was declared.
  6. Stack trace showing the function call sequence leading to the error.

Repair

This error is normally straightforward to correct based on the information presented in the diagnostic output.

The simplest solution is to change the definition of the array in the called routine to indicate an array of unknown size, i.e., replace line 5 with

	parmrnge.c, 5      int a[];

This declaration will match any array argument and is the recommended approach whenever the called routine will accept arrays of variable size.

An alternative is to change the declaration of the array in the calling routine to match that expected. In this case, line 10 could be changed to

	parmrnge.c, 10      int b[10];

which now matches the argument declaration.


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