Don't return invalid buffer from wxConvertToGTK("").

The result of wxConvertToGTK() is often passed to GTK+ functions directly and
not all of them handle NULLs gracefully, e.g. gtk_editable_insert_text() just
crashes.

Return an empty string from wxConvertToGTK() explicitly for empty string input
to avoid such problems.

Another potential solution might have been to change wxMBConv::cMB2WC() to
return empty buffer instead of invalid one for empty input but it's not clear
if this is not going to break something else.

Closes #12432.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65826 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-10-16 18:10:58 +00:00
parent 817b7b0e87
commit dd5ab30d6a

View File

@@ -116,6 +116,12 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
WXDLLIMPEXP_CORE wxCharBuffer WXDLLIMPEXP_CORE wxCharBuffer
wxConvertToGTK(const wxString& s, wxFontEncoding enc) wxConvertToGTK(const wxString& s, wxFontEncoding enc)
{ {
// Passing an empty string to cMB2WC() returns an invalid buffer, i.e. a
// buffer whose data is NULL and this can result in passing NULL to a GTK+
// function and a crash, so handle this case specially to avoid this.
if ( s.empty() )
return wxCharBuffer("");
wxWCharBuffer wbuf; wxWCharBuffer wbuf;
if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT ) if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT )
{ {