We recommend using Visual Studio 2017

C6383

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

For the latest documentation on Visual Studio 2017, see C6383 on docs.microsoft.com. 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...  
}   

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

Show: