Page tree

Skip to end of metadata
Go to start of metadata

In this section:


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


Array parameter exceeded range



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

 * File: leakscop.c
 * File: parmrnge.c
int foo(a)
	int a[10];
	return a[5];

int b[5];

	int a;
	a = foo(b);
	return (0);

Diagnosis at Runtime

[parmrnge.c:5] **PARM_BAD_RANGE**
>>	 {
		Array parameter exceeded range: a
						| 20 | 20 |
		Parameter (p)	0xf7fffb04 thru 0xf7fffb2b (40 bytes)
	Actual block (b)	0xf7fffb04 thru 0xf7fffb17
						(20 bytes, 5 elements)
					b, declared at parmrnge.c, 10
Stack trace where the error occurred:
			foo() parmrnge.c, 5
			main() parmrnge.c, 15
  • Line 2: Source file and line at which the problem was detected.
  • Line 3: Description of the problem and the name of the parameter that is in error.
  • Line 4: Schematic showing the relative layout of the memory block which was actually passed as the argument (b) and expected parameter (p). Also see Overflow Diagrams.
  • Line 7: Description of the memory range occupied by the parameter, including its length.
  • Line 10: 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.
  • Line 13: Stack trace showing the function call sequence leading to the error.


This error is normally easy 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 the following:

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 the following, which would match the argument declaration:

parmrnge.c, 10 int b[10];

  • No labels