PTR-uninit
In this section:
Synopsis
Dereference of an uninitialized or NULL pointer.
Enabled by default
Yes
Severity/Certainty
High/Medium

Full description
An uninitialized pointer value is being dereferenced. This might cause memory corruption or an application crash. Pointer values must be initialized before being dereferenced. This check is identical to MISRAC2004-9.1_c, MISRAC++2008-8-5-1_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:2004 9.1
(Required) All automatic variables shall have been assigned a value before being used.
- MISRA C++ 2008 8-5-1
(Required) All variables shall have a defined value before they are used.
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
}