CERT-EXP34-C_c
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-assign-pos.
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 <string.h>
char *getenv(const char *name)
{
return strcmp(name, "HOME")==0 ? "/" : NULL;
}
int ex(void)
{
char *p = getenv("USER");
return *p; //p might be NULL
}
The following code example passes the check and will not give a warning about this issue:
#include <stdlib.h>
int main(void)
{
int *p = malloc(sizeof(int));
if (p != 0) {
*p = 4;
}
return (int)p;
}