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

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

View File

@@ -355,7 +355,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
@@ -368,10 +370,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;