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 violationSolution
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 violationSolution
Correct logic errors, or remove the _Nonnull attribute and rework the called function’s logic accordingly.
See Also
Undefined Behavior Sanitizer
Misaligned pointerInvalid Boolean valueOut-of-bounds array accessInvalid enumeration valueReaching of unreachable pointDynamic type violationInvalid float castDivision by zeroNonnull return value violationNonnull variable assignment violationNull reference creation and null pointer dereferenceInvalid object sizeInvalid shiftInteger overflowInvalid variable-length array