fix for potential crash when conversion fails

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39886 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2006-06-29 08:16:49 +00:00
parent 1ae82ba9f2
commit a0ef88bde8

View File

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