]> git.saurik.com Git - wxWidgets.git/commitdiff
Use wxString::To8BitData() instead of mb_str() to handle NULs correctly.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Nov 2010 13:53:40 +0000 (13:53 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Nov 2010 13:53:40 +0000 (13:53 +0000)
In ANSI build wxString::mb_str() returns a pointer to the internal wxString
data directly instead of a buffer with a proper length, so it provides access
to the part of the string before the first embedded NUL only.

Use To8BitData() which always returns the buffer of the correct size in all
builds.

The open question remains whether mb_str() should be changed to return a (non
owned) buffer and not just a pointer in ANSI build. This would make
manipulating strings with embedded NULs safer but mb_str() would be less
efficient and less compatible.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66102 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/streams/sstream.cpp

index f94d0373507c7240ca6dae187317520c653b5fd8..3d65dd7eae8566376a1bd310f04fbcdc7019617c 100644 (file)
@@ -106,7 +106,7 @@ void strStream::CheckString(const wxString& text)
 {
     wxStringOutputStream sos;
 
-    const wxCharBuffer buf(text.mb_str());
+    const wxCharBuffer buf(text.To8BitData());
     sos.Write(buf, buf.length());
 
     CPPUNIT_ASSERT_EQUAL( text, sos.GetString() );