In this section:
This error is generated whenever an uninitialized pointer is dereferenced.
|
The following code attempts to use the value of the pointer a
, even though it has not been initialized.
/* * File: writuptr.c */ main() { int *a; *a = 123; return (0); } |
[writuptr.c:8] **WRITE_UNINIT_PTR** >> *a = 123; Writing to an 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() writuptr.c, 8 **Memory corrupted. Program may crash!!** |
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: writuptr.c (Modified) */ main() { int *a, b; a = &b; *a = 123; } |
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 |