Aracılığıyla paylaş


C6200

warning C6200: index <name> is out of valid index range <min> to <max> for non-stack buffer <variable>

This warning indicates that an integer offset into the specified array exceeds the maximum bounds of that array. This defect might cause random behavior or crashes.

One common cause of this defect is using the size of an array as an index into the array. Because C/C++ array indexing is zero-based, the maximum legal index into an array is one less than the number of array elements.

Example

The following code generates this warning because the for loop exceeds the index range:

int buff[14]; // array of 0..13 elements
void f()
{
   for (int i=0; i<=14;i+) // i exceeds the index
   {
     buff[i]= 0; // warning C6200 
     // code...
   }
}

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

int buff[14]; // array of 0..13 elements
void f()
{
   for ( int i=0; i < 14; i+) // loop stops when i < 14 
   {
     buff[i]= 0; // initialize buffer
    // code...
   }
}