X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e27a15e1468268204eae0c4299ecb1ae789e0881..77a1771911ed222ba6861ead327c3735fc16a0b1:/src/common/strconv.cpp?ds=sidebyside diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index 4e610d300c..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__ @@ -150,7 +150,8 @@ static size_t decode_utf16(const wxUint16* input, wxUint32& output) static wxUint32 wxDecodeSurrogate(const wxDecodeSurrogate_t **pSrc) { wxUint32 out; - const size_t n = decode_utf16(wx_reinterpret_cast(wxUint16 *, *pSrc), out); + const size_t + n = decode_utf16(wx_reinterpret_cast(const wxUint16 *, *pSrc), out); if ( n == wxCONV_FAILED ) *pSrc = NULL; else @@ -178,7 +179,7 @@ wxMBConv::ToWChar(wchar_t *dst, size_t dstLen, size_t dstWritten = 0; // the number of NULs terminating this string - size_t nulLen wxDUMMY_INITIALIZE(0); + size_t nulLen = 0; // not really needed, but just to avoid warnings // if we were not given the input size we just have to assume that the // string is properly terminated as we have no way of knowing how long it @@ -421,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 ) @@ -432,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; } } @@ -2759,7 +2763,7 @@ public: { OSStatus status = noErr ; ByteCount byteOutLen ; - ByteCount byteInLen = strlen(psz) ; + ByteCount byteInLen = strlen(psz) + 1; wchar_t *tbuf = NULL ; UniChar* ubuf = NULL ; size_t res = 0 ; @@ -3394,6 +3398,7 @@ WXDLLIMPEXP_DATA_BASE(wxCSConv&) wxConvISO8859_1 = wxConvISO8859_1Obj; WXDLLIMPEXP_DATA_BASE(wxMBConvUTF7&) wxConvUTF7 = wxConvUTF7Obj; WXDLLIMPEXP_DATA_BASE(wxMBConvUTF8&) wxConvUTF8 = wxConvUTF8Obj; WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvCurrent = &wxConvLibcObj; +WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvUI = &wxConvLocal; WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = & #ifdef __WXOSX__ wxConvUTF8Obj; @@ -3401,7 +3406,6 @@ WXDLLIMPEXP_DATA_BASE(wxMBConv *) wxConvFileName = & wxConvLibcObj; #endif - #else // !wxUSE_WCHAR_T // stand-ins in absence of wchar_t