fix off by one bug in the buffer size (fixes #10039)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@56246 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-10-12 14:51:45 +00:00
parent cebbcdcf5e
commit 27895e2f37
3 changed files with 55 additions and 3 deletions

View File

@@ -332,7 +332,9 @@ wxMBConv::FromWChar(char *dst, size_t dstLen,
size_t wxMBConv::MB2WC(wchar_t *outBuff, const char *inBuff, size_t outLen) const
{
size_t rc = ToWChar(outBuff, outLen, inBuff);
// add 1 to available buffer length because MB2WC() parameter counts the
// number of non-NUL characters while ToWChar() counts everything
size_t rc = ToWChar(outBuff, outLen + 1, inBuff);
if ( rc != wxCONV_FAILED )
{
// ToWChar() returns the buffer length, i.e. including the trailing
@@ -345,10 +347,12 @@ size_t wxMBConv::MB2WC(wchar_t *outBuff, const char *inBuff, size_t outLen) cons
size_t wxMBConv::WC2MB(char *outBuff, const wchar_t *inBuff, size_t outLen) const
{
size_t rc = FromWChar(outBuff, outLen, inBuff);
const size_t nulLen = GetMBNulLen();
size_t rc = FromWChar(outBuff, outLen + nulLen, inBuff);
if ( rc != wxCONV_FAILED )
{
rc -= GetMBNulLen();
rc -= nulLen;
}
return rc;