Re: Have read the documentation, and am confused

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Relvinian (smpres_at_hotmail.com)
Date: 12/08/04


Date: Wed, 08 Dec 2004 01:21:41 -0700

Bonj wrote:
> Hi
> The third and fifth parameters for wcstombs_s are listed as
>
> [in]sizeInBytes
> Buffer size for mbstr.
> [in] count
> The maximum number of bytes that can be stored in the multibyte output
> string.
> What is the difference between the two? Surely the "buffer size" is *defined
> as* "the maximum number of bytes that can be stored" in it? Would the two
> ever be different?
>
>
>
Since I don't have the beta of 2005 and can't really say, I'm taking a
stab at it. I would say that the documentation is "not correct" and
should read something like this for the 5th parameter:
"The maximum number of characters that can be stored in the multibyte
output string".

If you go with that assumption, the buffer length and number of
characters are different values. For example:

#define MAX_CHARACTERS 100
w_char* buffer = new w_char[100];

; do something with buffer

delete[] buffer;

Here, the actual size of 'buffer' is 200 because w_char is a multibyte
character. But the number of characters you can put into this buffer is
only 100 without going out-of-bounds.

Relvinian



Relevant Pages

  • [UNIX] wu-ftpd fb_realpath() Off-by-One Bug
    ... Wu-ftpd FTP server contains remotely exploitable off-by-one bug. ... characters while the size of the buffer is MAXPATHLEN characters only. ... Following FTP commands may be used to cause buffer overflow: ...
    (Securiteam)
  • Re: Serial Port CE_OVERRUN errors
    ... SerialNG component. ... The main Input buffer is set to 32000, and I have a variable which is ... updated with the maximum number of characters waiting there each time the ... I tried boosting the baud rate from 57.6k to 115.2k, ...
    (comp.lang.pascal.delphi.misc)
  • Re: WaitCommEvent and ResetEvent for SerialPort
    ... This is extremely true when you say you are exhausting the input buffer, ... This receiver thread will then signal your main ... >> From the WaitCommEvent documentation, ... Since no characters are currently coming it, ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Copy to CStrings internal buffer
    ... I know that this buffer is 20 characters long; ... conditions would I use memcpy, because a CString is not necessarily 8-bit characters! ...
    (microsoft.public.vc.mfc)
  • _sntprintf and _sntprintf_s
    ... _snwprintf was declared with old syntax. ... There is some difference between a VC++ built-in header declaring a function ... This really specifies the size of the buffer. ... Count parameter specifies a maximum number of characters. ...
    (microsoft.public.vc.language)