Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio Team System
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...
} 
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker