X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b903802e0838d2a5de8be099c8d764147fcc624c..575cabba69600557a34a08ddefad66628296ffad:/src/msw/debughlp.cpp diff --git a/src/msw/debughlp.cpp b/src/msw/debughlp.cpp index 8075dd672a..d2ddec0146 100644 --- a/src/msw/debughlp.cpp +++ b/src/msw/debughlp.cpp @@ -25,7 +25,7 @@ #include "wx/msw/debughlp.h" -#if wxUSE_DBGHELP +#if wxUSE_DBGHELP && wxUSE_DYNLIB_CLASS // ---------------------------------------------------------------------------- // constants @@ -145,7 +145,7 @@ const wxString& wxDbgHelpDLL::GetErrorMessage() void wxDbgHelpDLL::LogError(const wxChar *func) { ::OutputDebugString(wxString::Format(_T("dbghelp: %s() failed: %s\r\n"), - func, wxSysErrorMsg(::GetLastError()))); + func, wxSysErrorMsg(::GetLastError())).wx_str()); } // ---------------------------------------------------------------------------- @@ -391,7 +391,7 @@ wxDbgHelpDLL::DumpUDT(PSYMBOL_INFO pSym, void *pVariable, unsigned level) s.reserve(512); s = GetSymbolName(pSym); -#if !wxUSE_STL +#if !wxUSE_STD_STRING // special handling for ubiquitous wxString: although the code below works // for it as well, it shows the wxStringBase class and takes 4 lines // instead of only one as this branch @@ -399,13 +399,27 @@ wxDbgHelpDLL::DumpUDT(PSYMBOL_INFO pSym, void *pVariable, unsigned level) { wxString *ps = (wxString *)pVariable; - // take care to use c_str() here as otherwise we might hit an assert in - // wxString code if it is currently locked for writing (i.e. we're - // between GetWriteBuf() and UngetWriteBuf() calls) - s << _T("(\"") << ps->c_str() << _T(")\""); + // we can't just dump wxString directly as it could be corrupted or + // invalid and it could also be locked for writing (i.e. if we're + // between GetWriteBuf() and UngetWriteBuf() calls) and assert when we + // try to access it contents using public methods, so instead use our + // knowledge of its internals + const wxChar *p = NULL; + if ( !::IsBadReadPtr(ps, sizeof(wxString)) ) + { + p = ps->data(); + wxStringData *data = (wxStringData *)p - 1; + if ( ::IsBadReadPtr(data, sizeof(wxStringData)) || + ::IsBadReadPtr(p, sizeof(wxChar *)*data->nAllocLength) ) + { + p = NULL; // don't touch this pointer with 10 feet pole + } + } + + s << _T("(\"") << (p ? p : _T("???")) << _T(")\""); } else // any other UDT -#endif // !wxUSE_STL +#endif // !wxUSE_STD_STRING { // Determine how many children this type has. DWORD dwChildrenCount = 0;