]> git.saurik.com Git - wxWidgets.git/commitdiff
return empty string instead of NULL from mb_str()/wc_str() when conversion fails...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Apr 2009 17:48:11 +0000 (17:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 13 Apr 2009 17:48:11 +0000 (17:48 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60125 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/string.h

index 26fa4b4e4bd3cc542fdd95b474181c2e5e9721c8..a67e8e8fb973550c27139a5e6f3a0fdceeb1db0c 100644 (file)
@@ -3510,7 +3510,18 @@ private:
       // about it and doing it like this, i.e. having a separate AsChar(),
       // allows us to avoid the creation and destruction of a temporary buffer
       // when using wxCStrData without duplicating any code
-      AsChar(conv);
+      if ( !AsChar(conv) )
+      {
+          // although it would be probably more correct to return NULL buffer
+          // from here if the conversion fails, a lot of existing code doesn't
+          // expect mb_str() (or wc_str()) to ever return NULL so return an
+          // empty string otherwise to avoid crashes in it
+          //
+          // also, some existing code does check for the conversion success and
+          // so asserting here would be bad too -- even if it does mean that
+          // silently losing data is possible for badly written code
+          return wxScopedCharBuffer::CreateNonOwned("", 0);
+      }
 
       return m_convertedToChar.AsScopedBuffer();
   }
@@ -3529,7 +3540,8 @@ private:
   // wc_str() implementation helper
   wxScopedWCharBuffer AsWCharBuf(const wxMBConv& conv) const
   {
-      AsWChar(conv);
+      if ( !AsWChar(conv) )
+          return wxScopedWCharBuffer::CreateNonOwned(L"", 0);
 
       return m_convertedToWChar.AsScopedBuffer();
   }