Division by zero
Detects division where the divisor is zero.
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
}Solution
Modify the logic to check for and avoid division when the divisor might equal zero.
See Also
Undefined Behavior Sanitizer
Misaligned pointerInvalid Boolean valueOut-of-bounds array accessInvalid enumeration valueReaching of unreachable pointDynamic type violationInvalid float castNonnull argument violationNonnull return value violationNonnull variable assignment violationNull reference creation and null pointer dereferenceInvalid object sizeInvalid shiftInteger overflowInvalid variable-length array