]> git.saurik.com Git - wxWidgets.git/commitdiff
make string at least empty (instead of containing garbage) if malloc() failed
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 10 Jul 2003 12:07:53 +0000 (12:07 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 10 Jul 2003 12:07:53 +0000 (12:07 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21858 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/string.cpp

index 42863abaa81ac61538c19b36893323130520317f..4c61c07ee80bc07b85b74f06627259d54e5b8858 100644 (file)
@@ -260,17 +260,18 @@ wxString::wxString(const char *psz, wxMBConv& conv, size_t nLength)
         if ( !AllocBuffer(nLen) )
         {
             wxFAIL_MSG( _T("out of memory in wxString::wxString") );
-            return;
         }
-
-        // MB2WC wants the buffer size, not the string length
-        if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 )
+        else
         {
-            // initialized ok
-            m_pchData[nLen] = 0;
-            return;
+            // MB2WC wants the buffer size, not the string length
+            if ( conv.MB2WC(m_pchData, psz, nLen + 1) != (size_t)-1 )
+            {
+                // initialized ok
+                m_pchData[nLen] = 0;
+                return;
+            }
+            //else: the conversion failed -- leave the string empty (what else?)
         }
-        //else: the conversion failed -- leave the string empty (what else?)
     }
 
     Init();
@@ -301,16 +302,17 @@ wxString::wxString(const wchar_t *pwz, wxMBConv& conv, size_t nLength)
         if ( !AllocBuffer(nLen) )
         {
             wxFAIL_MSG( _T("out of memory in wxString::wxString") );
-            return;
         }
-
-        // WC2MB wants the buffer size, not the string length
-        if ( conv.WC2MB(m_pchData, pwz, nLen + 1) != (size_t)-1 )
+        else
         {
-            // initialized ok
-            return;
+            // WC2MB wants the buffer size, not the string length
+            if ( conv.WC2MB(m_pchData, pwz, nLen + 1) != (size_t)-1 )
+            {
+                // initialized ok
+                return;
+            }
+            //else: the conversion failed -- leave the string empty (what else?)
         }
-        //else: the conversion failed -- leave the string empty (what else?)
     }
 
     Init();