Export (0) Print
Expand All
Expand Minimize

C6383

warning C6383: buffer overrun due to conversion of an element count into a byte count: an element count is expected for parameter <number> in call to <function>

This warning indicates that a non-constant byte count is being passed when an element count is required. Typically, this occurs when a variable is multiplied by the sizeof a type, but code analysis suggests that an element count is required.

The following code generates this warning:

#include <string.h>

void f( wchar_t* t, wchar_t* s, int n )
{
  // code...
  wcsncpy (t, s, n*sizeof(wchar_t)); // warning 6383
  // code ...
}

To correct this warning, do not multiply the variable with the sizeof a type as shown in the following code:

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

The following code corrects this warning by using the safe string manipulation function:

void f(wchar_t* t, wchar_t* s, size_t n)
{
  // code...
  wcsncpy_s( t, sizeof(s), s, n );
  // code...
} 
Show:
© 2014 Microsoft