> For the complete documentation index, see [llms.txt](https://playbook.sidthoviti.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://playbook.sidthoviti.com/devsecops/secure-coding/code-review-examples/out-of-bounds.md).

# Out of Bounds

## Out of Bounds

**Example 1: C**

**Vulnerable Code:**

```c
cCopy codeint arr[10];
for (int i = 0; i <= 10; i++) {
    arr[i] = i;
}
```

**Reason for vulnerability:** Array index goes out of bounds, leading to undefined behavior.

**Fixed Code:**

```c
cCopy codeint arr[10];
for (int i = 0; i < 10; i++) {
    arr[i] = i;
}
```

**Reason for fix:** Ensure the array index is within bounds.

**Example 2: Python**

**Vulnerable Code:**

```python
pythonCopy codearr = [0] * 10
for i in range(11):
    arr[i] = i
```

**Reason for vulnerability:** Array index goes out of bounds, leading to an IndexError.

**Fixed Code:**

```python
pythonCopy codearr = [0] * 10
for i in range(10):
    arr[i] = i
```

**Reason for fix:** Ensure the array index is within bounds.
