<!--
{
  "documentType" : "article",
  "framework" : "Xcode",
  "identifier" : "/documentation/Xcode/invalid-variable-length-array",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Invalid variable-length array"
}
-->

# 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:

```occ
int invalid_index_returning_function() {
    return -1;
}
int idx = invalid_index_returning_function();
int array[idx]; // Error: invalid array length
```

#### Solution

Fix the issue by checking array bounds before constructing arrays.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)