X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f54cb154d59a7205b0f2829b5aea31882a379d60..491acfc75e9bf12806e177b655f3fb7df53e7602:/include/wx/string.h diff --git a/include/wx/string.h b/include/wx/string.h index 26fa4b4e4b..cc9e4dc8c8 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -209,7 +209,7 @@ inline int Stricmp(const char *psz1, const char *psz2) // Lightweight object returned by wxString::c_str() and implicitly convertible // to either const char* or const wchar_t*. -class WXDLLIMPEXP_BASE wxCStrData +class wxCStrData { private: // Ctors; for internal use by wxString and wxCStrData only @@ -408,6 +408,7 @@ protected: #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN // "non dll-interface class 'wxStringPrintfMixin' used as base interface // for dll-interface class 'wxString'" -- this is OK in our case + #pragma warning (push) #pragma warning (disable:4275) #endif @@ -1004,8 +1005,8 @@ public: { return iterator(str(), wxStringOperations::AddToIter(m_cur, -n)); } private: - iterator(wxString *str, underlying_iterator ptr) - : m_cur(ptr), m_node(str, &m_cur) {} + iterator(wxString *wxstr, underlying_iterator ptr) + : m_cur(ptr), m_node(wxstr, &m_cur) {} wxString* str() const { return const_cast(m_node.m_str); } @@ -1049,8 +1050,8 @@ public: private: // for internal wxString use only: - const_iterator(const wxString *str, underlying_iterator ptr) - : m_cur(ptr), m_node(str, &m_cur) {} + const_iterator(const wxString *wxstr, underlying_iterator ptr) + : m_cur(ptr), m_node(wxstr, &m_cur) {} const wxString* str() const { return m_node.m_str; } @@ -3510,7 +3511,18 @@ private: // about it and doing it like this, i.e. having a separate AsChar(), // allows us to avoid the creation and destruction of a temporary buffer // when using wxCStrData without duplicating any code - AsChar(conv); + if ( !AsChar(conv) ) + { + // although it would be probably more correct to return NULL buffer + // from here if the conversion fails, a lot of existing code doesn't + // expect mb_str() (or wc_str()) to ever return NULL so return an + // empty string otherwise to avoid crashes in it + // + // also, some existing code does check for the conversion success and + // so asserting here would be bad too -- even if it does mean that + // silently losing data is possible for badly written code + return wxScopedCharBuffer::CreateNonOwned("", 0); + } return m_convertedToChar.AsScopedBuffer(); } @@ -3529,7 +3541,8 @@ private: // wc_str() implementation helper wxScopedWCharBuffer AsWCharBuf(const wxMBConv& conv) const { - AsWChar(conv); + if ( !AsWChar(conv) ) + return wxScopedWCharBuffer::CreateNonOwned(L"", 0); return m_convertedToWChar.AsScopedBuffer(); } @@ -3564,7 +3577,7 @@ private: }; #ifdef wxNEEDS_WXSTRING_PRINTF_MIXIN - #pragma warning (default:4275) + #pragma warning (pop) #endif // string iterator operators that satisfy STL Random Access Iterator