---
title: Nonnull variable assignment violation
framework: xcode
role: article
role_heading: Article
path: xcode/nonnull-variable-assignment-violation
---

# Nonnull variable assignment violation

Detects when you incorrectly assign null to a variable.

## Overview

Overview Use this check to detect when you assign null to a variable with the _Nonnull annotation. Available in Xcode 9 and later. note: The nonnull violation check for variable assignment is off by default. You can turn it on by enabling the -fsanitize=nullability-assign compiler flag. 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

- [Misaligned pointer](xcode/misaligned-pointer.md)
- [Invalid Boolean value](xcode/invalid-boolean.md)
- [Out-of-bounds array access](xcode/out-of-bounds-array-access.md)
- [Invalid enumeration value](xcode/invalid-enumeration-value.md)
- [Reaching of unreachable point](xcode/reaching-of-unreachable-point.md)
- [Dynamic type violation](xcode/dynamic-type-violation.md)
- [Invalid float cast](xcode/invalid-float-cast.md)
- [Division by zero](xcode/division-by-zero.md)
- [Nonnull argument violation](xcode/nonnull-argument-violation.md)
- [Nonnull return value violation](xcode/nonnull-return-value-violation.md)
- [Null reference creation and null pointer dereference](xcode/null-reference-creation-and-null-pointer-dereference.md)
- [Invalid object size](xcode/invalid-object-size.md)
- [Invalid shift](xcode/invalid-shift.md)
- [Integer overflow](xcode/integer-overflow.md)
- [Invalid variable-length array](xcode/invalid-variable-length-array.md)
