Invalid variable-length array
Detects negative array bounds.
Overview
Use this check to detect negative array bounds. Variable-length arrays with a negative length have undefined behavior, and may cause stack corruption. Available in Xcode 9 and later.
Negative variable-length array bounds in C
In the following code, the call to the invalid_index_returning_function function returns a negative number that results in an invalid array:
int invalid_index_returning_function() {
return -1;
}
int idx = invalid_index_returning_function();
int array[idx]; // Error: invalid array lengthSolution
Fix the issue by checking array bounds before constructing arrays.
See Also
Undefined Behavior Sanitizer
Misaligned pointerInvalid Boolean valueOut-of-bounds array accessInvalid 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 overflow