Avoid converting empty strings to NULL pointers in non-Unicode build

...when using utf8_str() or wxGTK_CONV as argument to const char* function parameter
This commit is contained in:
Paul Cornett
2019-08-25 23:08:59 -07:00
parent db16c7af93
commit 536025791a
2 changed files with 9 additions and 2 deletions

View File

@@ -1709,7 +1709,11 @@ public:
{ return FromUTF8Unchecked(utf8.c_str(), utf8.length()); } { return FromUTF8Unchecked(utf8.c_str(), utf8.length()); }
#endif #endif
const wxScopedCharBuffer utf8_str() const const wxScopedCharBuffer utf8_str() const
{ return wxMBConvUTF8().cWC2MB(wc_str()); } {
if (empty())
return wxScopedCharBuffer::CreateNonOwned("", 0);
return wxMBConvUTF8().cWC2MB(wc_str());
}
#endif #endif
const wxScopedCharBuffer ToUTF8() const { return utf8_str(); } const wxScopedCharBuffer ToUTF8() const { return utf8_str(); }

View File

@@ -86,6 +86,9 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
WXDLLIMPEXP_CORE wxCharBuffer WXDLLIMPEXP_CORE wxCharBuffer
wxConvertToGTK(const wxString& s, wxFontEncoding enc) wxConvertToGTK(const wxString& s, wxFontEncoding enc)
{ {
if (s.empty())
return wxCharBuffer("");
wxWCharBuffer wbuf; wxWCharBuffer wbuf;
if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT ) if ( enc == wxFONTENCODING_SYSTEM || enc == wxFONTENCODING_DEFAULT )
{ {
@@ -96,7 +99,7 @@ wxConvertToGTK(const wxString& s, wxFontEncoding enc)
wbuf = wxCSConv(enc).cMB2WC(s.c_str()); wbuf = wxCSConv(enc).cMB2WC(s.c_str());
} }
if ( !wbuf && !s.empty() ) if (wbuf.length() == 0)
{ {
// conversion failed, but we still want to show something to the user // conversion failed, but we still want to show something to the user
// even if it's going to be wrong it is better than nothing // even if it's going to be wrong it is better than nothing