]> git.saurik.com Git - wxWidgets.git/commitdiff
fix for potential crash when conversion fails
authorStefan Csomor <csomor@advancedconcepts.ch>
Thu, 29 Jun 2006 08:16:49 +0000 (08:16 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Thu, 29 Jun 2006 08:16:49 +0000 (08:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/dc.cpp

index eb8b35a402e8dc7d022dbceba46dacd634b324a5..443bcdbb8b84bae93854a2cebb136dc1ff7dad68 100644 (file)
@@ -1782,17 +1782,25 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con
 #endif
     {
         wxCharBuffer buff = text.mb_str(wxConvLocal);
-        size_t len = strlen(buff);
-        short* measurements = new short[len+1];
-        MeasureText(len, buff.data(), measurements);
+        if ( buff.data() == 0 )
+        {
+            for (size_t i=0; i<text.length(); i++)
+                widths[i] = 0 ;
+        }
+        else
+        {
+            size_t len = strlen(buff);
+            short* measurements = new short[len+1];
+            MeasureText(len, buff.data(), measurements);
 
-        // Copy to widths, starting at measurements[1]
-        // NOTE: this doesn't take into account any multi-byte characters
-        // in buff, it probably should...
-        for (size_t i=0; i<text.length(); i++)
-            widths[i] = XDEV2LOGREL(measurements[i + 1]);
+            // Copy to widths, starting at measurements[1]
+            // NOTE: this doesn't take into account any multi-byte characters
+            // in buff, it probably should...
+            for (size_t i=0; i<text.length(); i++)
+                widths[i] = XDEV2LOGREL(measurements[i + 1]);
 
-        delete [] measurements;
+            delete [] measurements;
+        }
     }
 
     return true;