In this section:
Overview
This error is generated whenever an uninitialized pointer is passed as an argument to a function which expects an array parameter.
| Code | Description | Enabled | Reported |
|---|---|---|---|
| PARM_UNINIT_PTR | Array parameter is an uninitialized pointer | Runtime |
Problem
The following code passes the uninitialized pointer a to routine foo.
/*
* File: parmuptr.c
*/
char foo(a)
char a[10];
{
return a[0];
}
main()
{
char *a;
foo(a);
return (0);
}
Diagnosis at Runtime
[parmuptr.c:5] **PARM_UNINIT_PTR**
>> {
Array parameter is uninitialized pointer: a
Stack trace where the error occurred:
foo() parmuptr.c, 5
main() parmuptr.c, 14
- Line 2: Source line at which the problem was detected.
- Line 3: Description of the problem and the argument that is in error.
- Line 5: Stack trace showing the function call sequence leading to the error
Repair
This problem is usually caused by omitting an assignment or allocation statement that would initialize a pointer. The code given, for example, could be corrected by including an assignment as shown below.
/*
* File: parmuptr.c (Modified)
*/
...
main()
{
char *a, b[10];
a = b;
foo(a);
}