]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed bug #947908: wxString("abcdefghij", wxConvLibc, n) returns an empty string...
authorDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Fri, 7 May 2004 01:59:28 +0000 (01:59 +0000)
committerDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Fri, 7 May 2004 01:59:28 +0000 (01:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27131 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 9a0cff0e00abae665a9c6ea6617490ec3d615cfa..9b1de655cd4fd2f4a483506675861972b2383b8b 100644 (file)
@@ -970,9 +970,14 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
         }
         else
         {
-            wxWCharBuffer buf(nLen + 1);
+            // the input buffer to MB2WC must always be NUL-terminated
+            wxCharBuffer inBuf(nLen);
+            memcpy(inBuf.data(), psz, nLen);
+            inBuf.data()[nLen] = '\0';
+
+            wxWCharBuffer buf(nLen);
             // MB2WC wants the buffer size, not the string length hence +1
-            nLen = conv.MB2WC(buf.data(), psz, nLen + 1);
+            nLen = conv.MB2WC(buf.data(), inBuf.data(), nLen + 1);
 
             if ( nLen != (size_t)-1 )
             {