Contents

Nonnull argument violation

Detects when an argument incorrectly receives a null value.

Overview

Use this check to detect when a function that has an argument with the nonnull attribute or the _Nonnull annotation receives a null value. Available in Xcode 9 and later.

Violation of the nonnull parameter attribute in C

In the following example, the call to the has_nonnull_argument function breaks the nonnull attribute of the parameter p:

void has_nonnull_argument(__attribute__((nonnull)) int *p) { 
     // ... 
}
has_nonnull_argument(NULL); // Error: nonnull parameter attribute violation

Solution

Correct logic errors, or remove the nonnull attribute and rework the called function’s logic accordingly.

Violation of the nonnull annotation for an argument in C

In the following example, the call to the has_nonnull_argument function breaks the _Nonnull annotation of the parameter p:

void has_nonnull_argument(int * _Nonnull p) { 
     // ... 
}
has_nonnull_argument(NULL); // Error: _Nonnull annotation violation

Solution

Correct logic errors, or remove the _Nonnull attribute and rework the called function’s logic accordingly.

See Also

Undefined Behavior Sanitizer