From 28be59b4ad80f77be3b5581255db3bec20f575fe Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 9 Sep 2007 18:57:41 +0000 Subject: [PATCH] return empty string, not NULL, from wxCStrData::AsChar() if conversion to ANSI fails for compatibility with wxWidgets 2 and std::string git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48613 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/string.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/common/string.cpp b/src/common/string.cpp index d0a6a44569..db04dad972 100644 --- a/src/common/string.cpp +++ b/src/common/string.cpp @@ -235,6 +235,12 @@ const char* wxCStrData::AsChar() const // convert the string: wxCharBuffer buf(str->mb_str()); + // if it failed, return empty string and not NULL to avoid crashes in code + // written with either wxWidgets 2 wxString or std::string behaviour in + // mind: neither of them ever returns NULL and so we shouldn't neither + if ( !buf ) + return ""; + // FIXME-UTF8: do the conversion in-place in the existing buffer if ( str->m_convertedToChar && strlen(buf) == strlen(str->m_convertedToChar) ) @@ -261,6 +267,10 @@ const wchar_t* wxCStrData::AsWChar() const // convert the string: wxWCharBuffer buf(str->wc_str()); + // notice that here, unlike above in AsChar(), conversion can't fail as our + // internal UTF-8 is always well-formed -- or the string was corrupted and + // all bets are off anyhow + // FIXME-UTF8: do the conversion in-place in the existing buffer if ( str->m_convertedToWChar && wxWcslen(buf) == wxWcslen(str->m_convertedToWChar) ) -- 2.45.2