From cc03aebb53dd657e1ce115e0798a32c22f942bb8 Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Fri, 19 Apr 2024 18:56:01 +0200 Subject: [PATCH] [Windows] Fix client crash Signed-off-by: Vitalii Koshura --- lib/win_util.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/win_util.cpp b/lib/win_util.cpp index 0fccd84013..1d76ffd68c 100644 --- a/lib/win_util.cpp +++ b/lib/win_util.cpp @@ -139,30 +139,35 @@ std::string boinc_wide_to_ascii(const std::wstring& str) { char* windows_format_error_string( unsigned long dwError, char* pszBuf, int iSize ... ) { - DWORD dwRet; + DWORD dwRet = 0; LPSTR lpszTemp = NULL; - va_list args; + va_list args = NULL; va_start(args, iSize); - dwRet = FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM , - NULL, - dwError, - LANG_NEUTRAL, + try { + dwRet = FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + dwError, + LANG_NEUTRAL, #ifdef wxUSE_GUI - (LPWSTR)&lpszTemp, + (LPWSTR)&lpszTemp, #else - (LPSTR)&lpszTemp, + (LPSTR)&lpszTemp, #endif - 0, - &args - ); + 0, + &args + ); + } + catch(...) { + dwRet = 0; + } va_end(args); if (dwRet != 0) { // include the hex error code as well - snprintf(pszBuf, iSize, "%S (0x%x)", lpszTemp, dwError); + snprintf(pszBuf, iSize, "%s (0x%x)", lpszTemp, dwError); if (lpszTemp) { LocalFree((HLOCAL)lpszTemp); }