Edit

Share via


Warning C6412

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

Remarks

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

The code analysis tool may report this warning in error. It reports this warning when it can't reduce a complex expression that represents the buffer size, or the index used to access the buffer.

Code analysis name: POTENTIAL_WRITE_OVERRUN

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;