C6412

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6412: Potential buffer overrun while writing to buffer. The writable size is write_size bytes, but write_index bytes may be written.

This warning indicates that the value of the index that is used to write to the buffer can exceed the writeable size of the buffer.

Because the code analysis tool reports this warning when it cannot reduce a complex expression that represents the buffer size, or the index used to access the buffer, this warning might be reported in error.

Example

The following code generates this warning.

char *a = new char[strlen(InputParam)];  
a[10] = 1;  
delete[] a;  

The following code corrects this error.

int i = strlen(InputParam);  
char *a = new char[i];  
if (i > 10) a[10] = 1;  
delete[] a;