Warning C6385

Invalid data: accessing buffer-name, the readable size is size1 bytes, but size2 bytes may be read: Lines: x, y

Remarks

The readable extent of the buffer might be smaller than the index used to read from it. Attempts to read data outside the valid range leads to buffer overrun.

Code analysis name: READ_OVERRUN

Example

The following code generates this warning:

void f(unsigned int i)
{
   char a[20];
   char j;
   if (i <= 20)  // C6385
   {
      j = a[i];
   }
}

To correct this warning, use the following code:

void f(unsigned int i)
{
   char a[20];
   char j;
   if (i < 20)  // Okay
   {
      j = a[i];
   }
}

See also

Avoiding buffer overruns