C6383

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 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.

Example

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...  
}   

See Also

strncpy_s, _strncpy_s_l, wcsncpy_s, _wcsncpy_s_l, _mbsncpy_s, _mbsncpy_s_l
sizeof Operator