In this section:
Overview
This error is generated whenever an uninitialized pointer is dereferenced.Code Description Enabled Reported Platform WRITE_UNINIT_PTR Writing to an uninitialized pointer Runtime Windows/Unix
Problem
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); }
Diagnosis at Runtime
[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!!**
- Line 2: Source line at which the problem was detected.
- Line 3: Description of the problem and the expression that is in error.
- Line 5-8: CWEs associated with this problem.
- Line 10: Stack trace showing the call sequence leading to the error.
- Line 12: Informational message indicating that a serious error has occurred which may cause the program to crash.
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: writuptr.c (Modified) */ main() { int *a, b; a = &b; *a = 123; }
References
The table below shows Common Weakness Enumerations associated with this error.