Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio Team System
C6201

warning C6201: buffer overrun for <variable>, which is possibly stack allocated: index <name> is out of valid index range <min> to <max>

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

One common cause of this defect is using an array’s size 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.

The following code generates this warning because the array index is out of the valid range:

void f( )
{
  int buff[25];
  for (int i=0; i <= 25; i++) // i exceeds array bound
  {
    buff[i]=0; // initialize i
    // code ...
  }
}

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

void f( )
{
  int buff[25];
  for (int i=0; i < 25; i++)
  {
    buff[i]=0; // initialize i
    // code ...
  }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker