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 non-stack buffer '\**parameter-name*'
13
13
14
-
This warning indicates that an integer offset into the specified array exceeds the maximum bounds of that array, potentially causing random behavior and/or crashes.
14
+
This warning indicates that an integer offset into the specified non-stack array exceeds the maximum bounds of that array, potentially causing random behavior and/or crashes.
The following code generates this warning. This issue stems from the **`for`** loop exceeding the index range, attempting to access index 14 (the 15th element) when index 13 (the 14th element) is the last:
25
25
26
26
```cpp
27
-
int buff[14]; // array of 0..13 elements
28
27
voidf()
29
28
{
29
+
int* buff = new int[14]; // array of 0..13 elements
30
30
for (int i = 0; i <= 14; i++) // i exceeds the index
31
31
{
32
32
buff[i] = 0; // warning C6200
33
33
}
34
+
delete buff;
34
35
}
35
36
```
36
37
37
38
To correct both warnings, use correct array size as shown in the following code:
38
39
39
40
```cpp
40
-
int buff[14]; // array of 0..13 elements
41
41
voidf()
42
42
{
43
+
int* buff = new int[14]; // array of 0..13 elements
43
44
for (int i = 0; i < 14; i++) // i == 13 on the final iteration
0 commit comments