Contents

Out-of-bounds array access

Detects out-of-bounds access of arrays.

Overview

Use this check to detect attempts to access indexes that exceed the array’s bounds. Out-of-bounds array accesses have undefined behavior, and can result in crashes or incorrect program output. Available in Xcode 9 and later.

Out-of-bounds array access in C

In the following example, out-of-bounds access of array occurs on the last iteration of the loop:

int array[5];
for (int i = 0; i <= 5; ++i) {
    array[i] += 1; // Error: out-of-bounds access on the last iteration
}

Solution

Ensure that accessed indexes don’t exceed the array’s bounds.

See Also

Undefined Behavior Sanitizer