Static Analysis Problem Type Reference

Pointer is only sometimes checked for null

A pointer was checked for null before some uses but not others.

This diagnostic is emitted when a pointer value is sometimes checked for null before use and sometimes not. If the pointer cannot be null, then no checks are needed. If the pointer can be null, then all uses should be protected with a check for null.

ID

Code Location

Description

1

Null dereference

The place where the pointer was used without checking for null

2

Memory read

The place where the pointer was earlier checked for null

Example


#include <stdio.h>

int main(int argc, char **argv)
{
    char *arg1 = argv[1];
    if (arg1 == 0) {
        printf("argument 1 is null!\n");
    }
    // oops: used arg1 without checking that is wasn't null
    printf("argument value is '%c'\n", *arg1);
}