]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't return invalid buffer from wxConvertToGTK("").
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 16 Oct 2010 18:10:58 +0000 (18:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 16 Oct 2010 18:10:58 +0000 (18:10 +0000)
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

src/gtk/utilsgtk.cpp

index 93b8f02790f29680f0e163f17b9083c6253d6fe7..8e36cc40b79f559566e94691df98d5033bc6ea37 100644 (file)
@@ -116,6 +116,12 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
 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 )
     {