lib: Only process FormatMessage output if the function succeeds. The CC calls windows_format_error_string() for all non-zero returns.

This commit is contained in:
Rom Walton 2013-01-29 12:47:26 -05:00 committed by Oliver Bock
parent 4a4678aeb9
commit c448732249
1 changed files with 8 additions and 6 deletions

View File

@ -901,14 +901,16 @@ char* windows_format_error_string(
NULL
);
// convert from current character encoding into UTF8
std::string encoded_message = W2A(std::wstring(lpszTemp));
if (dwRet != 0) {
// convert from current character encoding into UTF8
std::string encoded_message = W2A(std::wstring(lpszTemp));
// include the hex error code as well
snprintf(pszBuf, iSize, "%s (0x%x)", encoded_message.c_str(), dwError);
// include the hex error code as well
snprintf(pszBuf, iSize, "%s (0x%x)", encoded_message.c_str(), dwError);
if (lpszTemp) {
LocalFree((HLOCAL) lpszTemp);
if (lpszTemp) {
LocalFree((HLOCAL) lpszTemp);
}
}
return pszBuf;