Contents

Nonnull variable assignment violation

Detects when you incorrectly assign null to a variable.

Overview

Use this check to detect when you assign null to a variable with the _Nonnull annotation. Available in Xcode 9 and later.

Violation of nonnull annotation with variable assignment in C

In the following example, the call to assigns_a_value breaks the _Nonnull annotation of the variable q:

void assigns_a_value(int *p) {     
    int *_Nonnull q = p; // Warning: null can be assigned
}
assigns_a_value(NULL); // Error: _Nonnull variable violation

Solution

Correct logic errors, or remove the _Nonnull annotation.

See Also

Undefined Behavior Sanitizer