PTR-uninit-pos
In this section:
Synopsis
Possible dereference of an uninitialized or NULL pointer.
Enabled by default
No
Severity/Certainty
Low/High

Full description
On some execution paths, an uninitialized pointer value is dereferenced. This might cause memory corruption or an application crash. Pointer values must be initialized on all execution paths that result in a dereference. This check is identical to MISRAC2012-Rule-9.1_a, CERT-EXP33-C_c.
Coding standards
- CERT EXP33-C
Do not reference uninitialized memory
- CWE 457
Use of Uninitialized Variable
- CWE 824
Access of Uninitialized Pointer
- MISRA C:2012 Rule-9.1
(Mandatory) The value of an object with automatic storage duration shall not be read before it has been set
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int *p;
*p = 4; //p is uninitialized
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int *p,a;
p = &a;
*p = 4; //OK - p holds a valid address
}