---
title: Integer overflow
framework: xcode
role: article
role_heading: Article
path: xcode/integer-overflow
---

# Integer overflow

Detects overflow in arithmetic.

## Overview

Overview Overflows result in undefined behavior. Use this check to detect overflows in addition, subtraction, multiplication, and division. Available in Xcode 9 and later. Signed addition overflow in C In the following code, the x variable has the maximum int32_t value before the addition, and the result of the addition overflows x, which the optimizer may not handle in a predictable way: int32_t x = (1U << 31) - 1; x += 1; // Error: the add result can't fit in x note: With the exception of the signed division check, enabling the -fwrapv compiler flag disables UBSan overflow checks. Solution One way to address signed overflow is to use larger types. If you don’t need to represent negative numbers, another option is to use unsigned types, which wrap on arithmetic overflow. Alternatively, pass the -fwrapv flag to the compiler to enable signed wraparound on overflow. However, this may adversely impact performance.

## 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)
- [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)
- [Invalid variable-length array](xcode/invalid-variable-length-array.md)
