Insure++ Reference - PARM_BAD_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.
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: {
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: }
[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
- Source line at which the problem was detected.
- Description of the problem and the name of the parameter
that is in error.
- Schematic showing the relative layout of the memory block
which was actually passed as the argument (
b ) and
expected parameter (p ). (See
Overflow diagrams )
- Description of the memory range occupied by the parameter,
including its length.
- 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.
- Stack trace showing the function call sequence leading to the
error.
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
|