forked from OSchip/llvm-project
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:
parent
5de2378f7e
commit
69c55edb18
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue