In this section:
This error is generated whenever an uninitialized pointer is dereferenced. Note: This error category will be disabled if full uninitialized memory checking is in effect (the default). In this case, errors are detected in the READ_UNINIT_MEM category instead.
|
The following code attempts to use the value of the a pointer, even though it has never been initialized.
/*
* File: readuptr.c
*/
main()
{
int b, *a;
b = *a;
return (0);
} |
[readuptr.c:8] **READ_UNINIT_PTR** >> b = *a; Reading from uninitialized pointer: a ---- Associated Common Weakness Enumerations ---- CWE-457: Use of uninitialized variable CWE-824: Access of uninitialized pointer CWE-908: Use of uninitialized resource Stack trace where the error occurred: main() readuptr.c, 8 |
This problem is usually caused by omitting an assignment or allocation statement that would initialize a pointer. The code given can be corrected by including an assignment as shown below.
/*
* File: readuptr.c (Modified)
*/
main()
{
int b, *a, c;
c = 1;
a = &c;
b = *a;
return (0);
} |
The table below shows Common Weakness Enumerations associated with this error.
| CWE | Description |
|---|---|
| CWE-457 | Use of uninitialized variable |
| CWE-824 | Access of uninitialized pointer |
| CWE-908 | Use of uninitialized resource |