CERT-EXP34-C_g
In this section:
Synopsis
Do not dereference null pointers.
Enabled by default
Yes
Severity/Certainty
High/High

Full description
Dereferencing a null pointer is undefined behavior. On many platforms, dereferencing a null pointer results in abnormal program termination, but this is not required by the standard. This check is identical to PTR-null-cmp-bef.
Coding standards
- CERT EXP34-C
Do not dereference null pointers
Code examples
The following code example fails the check and will give a warning:
#include <stdlib.h>
int example(void) {
int *p;
if (p == NULL) {
*p = 4; //dereference after comparison with NULL
}
return 1;
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
int example(void) {
int *p;
if (p != NULL) {
*p = 4; //OK - after comparison with non-NULL
}
return 1;
}