From dd5ab30d6a896e961a42fbfabd42c6415a1f388a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 16 Oct 2010 18:10:58 +0000 Subject: [PATCH] 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 --- src/gtk/utilsgtk.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 93b8f02790..8e36cc40b7 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -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 ) { -- 2.47.2