]> git.saurik.com Git - wxWidgets.git/commitdiff
don't allocate 0-sized buffer in cWC2MB() even if input size is 0
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 May 2006 18:49:47 +0000 (18:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 6 May 2006 18:49:47 +0000 (18:49 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39075 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/strconv.cpp

index eafce97c8b5b7029cad15cbb554bc9fd9a2f404a..4e62a144b1f028891048d082b4fc123ab8369176 100644 (file)
@@ -422,9 +422,15 @@ 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 )
     {
+        if ( !dstLen )
+        {
+            // special case: can't allocate 0 size buffer below
+            dstLen++;
+        }
+
         wxCharBuffer buf(dstLen - 1);
         if ( FromWChar(buf.data(), dstLen, inBuff, inLen) != wxCONV_FAILED )
         {
@@ -433,11 +439,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;
                 }
             }