From c448732249b6297b333d6aad51d82767e3135e5b Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Tue, 29 Jan 2013 12:47:26 -0500 Subject: [PATCH] lib: Only process FormatMessage output if the function succeeds. The CC calls windows_format_error_string() for all non-zero returns. --- lib/win_util.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/win_util.cpp b/lib/win_util.cpp index f4aa0e8997..cb213c06ab 100644 --- a/lib/win_util.cpp +++ b/lib/win_util.cpp @@ -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;