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


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];