Warning C6383

Buffer overrun due to conversion of an element count into a byte count: an element count is expected for parameter *parameter_name* in call to *function_name*

This warning indicates that a non-constant byte count is being passed when an element count is instead required.

Remarks

Typically, this warning occurs when a variable is multiplied by the sizeof a type. This issue will likely result in more bytes being copied to the buffer than it can hold.

Code analysis name: ELEMENTS_TO_BYTES

Example

The following code generates this warning. wcsncpy will allow n * sizeof(wchar_t) characters to be copied, but the buffer can only hold n characters. It should be noted that wcsncpy is an unsafe function, and shouldn't be used per C28719. The unsafe variant is used here only for the purposes of demonstrating this warning:

void f(wchar_t* t, wchar_t* s, int n)
{
    wcsncpy (t, s, n*sizeof(wchar_t));
}

The following code corrects this warning by sending element count instead of the byte count:

void f( wchar_t* t, wchar_t* s, int n )
{
    wcsncpy (t, s, n);
}

See also