From d0822e56c682d5919006f144599ffdaef9ab67e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 6 Jun 2005 22:05:16 +0000 Subject: [PATCH] don't crash if FormatMessage() fails in wxSysErrorMsg() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/log.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/common/log.cpp b/src/common/log.cpp index 37143c97c4..476f39db24 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -737,14 +737,26 @@ const wxChar *wxSysErrorMsg(unsigned long nErrCode) // get error message from system LPVOID lpMsgBuf; - FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, nErrCode, + if ( ::FormatMessage + ( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + nErrCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, - 0, NULL); + 0, + NULL + ) == 0 ) + { + // if this happens, something is seriously wrong, so don't use _() here + // for safety + wxSprintf(s_szBuf, _T("unknown error %lx"), nErrCode); + return s_szBuf; + } + // copy it to our buffer and free memory - // Crashes on SmartPhone + // Crashes on SmartPhone (FIXME) #if !defined(__SMARTPHONE__) /* of WinCE */ if( lpMsgBuf != 0 ) { wxStrncpy(s_szBuf, (const wxChar *)lpMsgBuf, WXSIZEOF(s_szBuf) - 1); -- 2.45.2