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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://playbook.sidthoviti.com/devsecops/secure-coding/code-review-examples/out-of-bounds.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
