Checking for a return value with FormatMessage; if the call fails, there's no guarantee that the buffer will be non-null.

llvm-svn: 195019
This commit is contained in:
Aaron Ballman 2013-11-18 17:43:22 +00:00
parent 5de2378f7e
commit 69c55edb18
1 changed files with 9 additions and 4 deletions

View File

@ -39,11 +39,16 @@ inline bool MakeErrMsg(std::string* ErrMsg, const std::string& prefix) {
if (!ErrMsg)
return true;
char *buffer = NULL;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
*ErrMsg = prefix + buffer;
DWORD R = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), 0, (LPSTR)&buffer, 1, NULL);
if (R)
*ErrMsg = prefix + buffer;
else
*ErrMsg = prefix + "Unknown error";
LocalFree(buffer);
return true;
return R != 0;
}
template <typename HandleTraits>