[Windows] Fix client crash

Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
This commit is contained in:
Vitalii Koshura 2024-04-19 18:56:01 +02:00
parent 627637d475
commit cc03aebb53
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
1 changed files with 19 additions and 14 deletions

View File

@ -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);
}