]> git.saurik.com Git - wxWidgets.git/commitdiff
fix crashes due to missing npos handling in several wxString methods in STL build...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 13 Apr 2008 23:41:15 +0000 (23:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 13 Apr 2008 23:41:15 +0000 (23:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/string.h
src/common/string.cpp

index a648beb6d7071f5a243150fb35a710181d748a90..cb6cf460a04262228278b8ef4e1991ee3084e66b 100644 (file)
@@ -431,7 +431,10 @@ private:
       size_t len;
 
       SubstrBufFromType(const T& data_, size_t len_)
-          : data(data_), len(len_) {}
+          : data(data_), len(len_)
+      {
+          wxASSERT_MSG( len != npos, "must have real length" );
+      }
   };
 
 #if wxUSE_UNICODE_UTF8
index a287759822baabf199d1bc79f2845cba128072b3..e68c7f03c0de6d5be491592661e754f45c317c86 100644 (file)
@@ -369,6 +369,9 @@ wxString::SubstrBufFromMB wxString::ConvertStr(const char *psz, size_t nLength,
         // UTF-8 sequence and psz may be invalid:
         if ( wxStringOperations::IsValidUtf8String(psz, nLength) )
         {
+            // we must pass the real string length to SubstrBufFromMB ctor
+            if ( nLength == npos )
+                nLength = psz ? strlen(psz) : 0;
             return SubstrBufFromMB(wxCharBuffer::CreateNonOwned(psz), nLength);
         }
         // else: do the roundtrip through wchar_t*