]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/strconv.cpp
Added Set/GetQuickBestSize
[wxWidgets.git] / src / common / strconv.cpp
index eafce97c8b5b7029cad15cbb554bc9fd9a2f404a..f4a58755c3cb3f2a983cb4c2bb6fa1a31614a718 100644 (file)
@@ -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;
                 }
             }