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
Misaligned pointerInvalid Boolean valueInvalid enumeration valueReaching of unreachable pointDynamic type violationInvalid float castDivision by zeroNonnull argument violationNonnull return value violationNonnull variable assignment violationNull reference creation and null pointer dereferenceInvalid object sizeInvalid shiftInteger overflowInvalid variable-length array