Skip to content

Commit 0ec7a28

Browse files
Updated C6200
Made example more obvious that the array was heap-allocated
1 parent af426b5 commit 0ec7a28

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

docs/code-quality/c6200.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.assetid: bbeb159b-4e97-4317-9a07-bb83cd03069a
1111

1212
> Index '\**index*' is out of valid index range '\**min*' to '\**max*' for non-stack buffer '\**parameter-name*'
1313
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.
1515

1616
## Remarks
1717

@@ -24,25 +24,27 @@ Code analysis name: INDEX_EXCEEDS_MAX_NONSTACK
2424
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:
2525

2626
```cpp
27-
int buff[14]; // array of 0..13 elements
2827
void f()
2928
{
29+
int* buff = new int[14]; // array of 0..13 elements
3030
for (int i = 0; i <= 14; i++) // i exceeds the index
3131
{
3232
buff[i] = 0; // warning C6200
3333
}
34+
delete buff;
3435
}
3536
```
3637

3738
To correct both warnings, use correct array size as shown in the following code:
3839

3940
```cpp
40-
int buff[14]; // array of 0..13 elements
4141
void f()
4242
{
43+
int* buff = new int[14]; // array of 0..13 elements
4344
for (int i = 0; i < 14; i++) // i == 13 on the final iteration
4445
{
4546
buff[i] = 0; // initialize buffer
4647
}
48+
delete buff;
4749
}
4850
```

0 commit comments

Comments
 (0)