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
WXDLLIMPEXP_CORE wxCharBuffer
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;
if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT )
{