Insure++ Reference - PARM_NULL
This error is generated whenever a parameter declared as an array is
actually passed a NULL pointer.
The following code fragment shows a function which is declared as
having an array parameter, but which is invoked with a
NULL pointer. The value of array
is NULL because it is a global variable, initialized
to zero by default.
1: /*
2: * File: parmnull.c
3: */
4: int foo(a)
5: int a[];
6: {
7: return 12;
8: }
9:
10: int *array;
11:
12: main()
13: {
14: foo(array);
15: return (0);
16: }
[parmnull:6] **PARM_NULL**
1. >> {
2. Array parameter is null: a
Stack trace where the error occurred:
3. foo() parmnull.c, 6
main() parmnull.c, 14
- Source line at which the problem was detected.
- Description of the problem and the name of the parameter
that is in error.
- Stack trace showing the function call sequence leading to
the error.
A common cause of this error is the one given in this example, a
global pointer which is initialized to zero by the compiler and then
never reassigned. The correction for this case is to include code to
initialize the pointer, possibly by allocating dynamic memory or by
assigning it to some other array object.
For example, we could change the main routine of the
example to
main()
{
int local[10];
array = local;
foo(array);
}
This problem can also occur when a pointer is set to
NULL by the code (perhaps to indicate a freed
block of memory) and then passed to a routine that expects an array
as an argument.
In this case, Insure++ distinguishes between functions whose
arguments are declared as arrays
int foo(int a[])
{
and those with pointer arguments
int foo(int *a)
{
The latter type will not generate an error if passed a
NULL argument, while the former will.
A final common problem is caused when one of the dynamic memory
allocation routines, malloc, calloc, or
realloc , fails and returns a NULL
pointer. This can happen either because your program passes bad arguments
or simply because it asks for too much memory. A simple way of finding
this problem with Insure++ is to enable the
RETURN_FAILURE
error code via your .psrc file and run
the program again. It will then issue diagnostic messages every time a
system call fails, including the memory allocation routines.
If your application cannot avoid passing a NULL
pointer to a routine, you should either change the declaration of its
argument to the second style or suppress these error messages by adding
the option
insure++.suppress PARM_NULL
to the .psrc file.
PARM_DANGLING
PARM_UNINIT_PTR
|