X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a78c43f158671390e8a129605c9ad088aac9e572..77a1771911ed222ba6861ead327c3735fc16a0b1:/src/common/strconv.cpp diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 92b18ad615..f4a58755c3 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -18,6 +18,7 @@ #ifndef WX_PRECOMP #include "wx/intl.h" #include "wx/log.h" + #include "wx/utils.h" #endif #include "wx/strconv.h" @@ -52,7 +53,6 @@ #include "wx/encconv.h" #include "wx/fontmap.h" -#include "wx/utils.h" #ifdef __WXMAC__ #ifndef __DARWIN__ @@ -422,10 +422,12 @@ wxMBConv::cMB2WC(const char *inBuff, size_t inLen, size_t *outLen) const const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const { - const size_t dstLen = FromWChar(NULL, 0, inBuff, inLen); + size_t dstLen = FromWChar(NULL, 0, inBuff, inLen); if ( dstLen != wxCONV_FAILED ) { - wxCharBuffer buf(dstLen - 1); + // special case of empty input: can't allocate 0 size buffer below as + // wxCharBuffer insists on NUL-terminating it + wxCharBuffer buf(dstLen ? dstLen - 1 : 1); if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED ) { if ( outLen ) @@ -433,11 +435,12 @@ wxMBConv::cWC2MB(const wchar_t *inBuff, size_t inLen, size_t *outLen) const *outLen = dstLen; const size_t nulLen = GetMBNulLen(); - if ( !NotAllNULs(buf.data() + dstLen - nulLen, nulLen) ) + if ( dstLen >= nulLen && + !NotAllNULs(buf.data() + dstLen - nulLen, nulLen) ) { // in this case the output is NUL-terminated and we're not // supposed to count NUL - (*outLen) -= nulLen; + *outLen -= nulLen; } }