---
title: Division by zero
framework: xcode
role: article
role_heading: Article
path: xcode/division-by-zero
---

# Division by zero

Detects division where the divisor is zero.

## Overview

Overview Use this check to detect integer and float division where the divisor is zero. Division by zero has undefined behavior, and can result in crashes or incorrect program output. Available in Xcode 9 and later. Integer division by zero in C In the following code, the for loop performs division by zero on its first iteration: int sum = 10; for (int i = 0; i < 64; ++i) {     sum /= i; // Error: division by zero on the first iteration } note: The optimizer may remove parts of a loop if it determines that undefined behavior might trigger in any of its iterations. Solution Modify the logic to check for and avoid division when the divisor might equal zero.

## 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)
- [Nonnull argument violation](xcode/nonnull-argument-violation.md)
- [Nonnull return value violation](xcode/nonnull-return-value-violation.md)
- [Nonnull variable assignment violation](xcode/nonnull-variable-assignment-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)
