You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> index '*index*' is out of valid index range '*min*' to '*max*' for possibly stack allocated buffer '*parameter-name*'
12
+
> Index '*index-name*' is out of valid index range '*minimum*' to '*maximum*' for possibly stack allocated buffer '*variable*'
13
13
14
-
This warning indicates that an integer offset into the specified stack array exceeds the maximum bounds of that array, potentially causing stack overflow, random behavior, and/or crashes.
14
+
This warning indicates that an integer offset into the specified stack array exceeds the maximum bounds of that array. It may potentially cause stack overflow errors, random behavior, or crashes.
The following code generates this warning. This issue stems from the **`for`** loop exceeding the index range, attempting to access the index 14 (the 15th element) when the index 13 (the 14th element) is the last:
24
+
The following code generates warning C6201. The **`for`** loop condition exceeds the valid index range for `buff` when it sets `i` to 14, which is one element past the end:
25
25
26
26
```cpp
27
27
voidf()
28
28
{
29
29
int buff[14]; // array of 0..13 elements
30
-
for (int i = 0; i <= 14; i++) // i exceeds the index
30
+
for (int i = 0; i <= 14; i++) // i == 14 exceeds the bounds
31
31
{
32
-
buff[i] = 0;
32
+
buff[i] = 0; // initialize buffer
33
33
}
34
34
}
35
35
```
36
36
37
-
To correct both warnings, use correct array size as shown in the following code:
37
+
To correct the warning, make sure the index stays in bounds. The following code shows the corrected loop condition:
0 commit comments