]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/string.cpp
Do not realize the top level shell that acts as a parent
[wxWidgets.git] / src / common / string.cpp
index aa461904f498b58daab618ee883fb97f27159fc8..9b1de655cd4fd2f4a483506675861972b2383b8b 100644 (file)
@@ -100,6 +100,8 @@ extern const wxChar WXDLLIMPEXP_BASE *wxEmptyString = &g_strEmpty.dummy;
 //
 // ATTN: you can _not_ use both of these in the same program!
 
+#include <iostream>
+
 wxSTD istream& operator>>(wxSTD istream& is, wxString& WXUNUSED(str))
 {
 #if 0
@@ -968,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 )
             {