In this section:
Overview
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.
There are several causes for this error to occur:
- Errors in user code that result in pointers that don’t 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.
This section focuses on the first type of problem described above. For information about the second type of problem, contact Parasoft’s Quality Consultants.
Code | Description | Enabled | Reported | Platform |
---|---|---|---|---|
PARM_WILD | Array parameter is wild | Runtime | Windows/Unix |
Problem 1
The following code attempts to pass the address of a local variable to the routine foo
, but it contains an error at line 14; the address operator (&
) has been omitted.
/* * File: parmwld1.c */ void foo(a) int a[]; { return; } main() { int i = 123, *a; a = i; foo(a); return (0); }
Diagnosis at Runtime
[parmwld1.c:5] **PARM_WILD** >> { Array parameter is wild: a Pointer : 0x0000007b Stack trace where the error occurred: foo() parmwld1.c, 5 main() parmwld1.c, 15
- Line 2: Source 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: Value of the bad pointer.
- Line 6: Stack trace showing the function call sequence leading to the error.
Problem 2
Another more difficult-to-identify 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.
/* * File: parmwld2.c */ union { int *ptr; int ival; } u; void foo(a) int a[]; { return; } main() { int i = 123; u.ptr = (int *)&i; u.ival = i; foo(u.ptr); return (0); }
This code will not generate compile time errors.
Diagnosis at Runtime
[parmwld2.c:11] **PARM_WILD** >> { Array parameter is wild: a Pointer : 0x0000007b Stack trace where the error occurred: foo() parmwld2.c, 11 main() parmwld2.c, 21
- Line 2: Source 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: Value of the bad pointer.
- Line 6: 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.
Wild pointers can also be generated when Insure++ has only partial information about your program’s structure. For more information about this topic, contact Parasoft’s Quality Consultants.