Skip to content

Commit

Permalink
Checking for a return value with FormatMessage; if the call fails, th…
Browse files Browse the repository at this point in the history
…ere's no guarantee that the buffer will be non-null.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@195019 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
AaronBallman committed Nov 18, 2013
1 parent eae6e54 commit 7c5498e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Support/Windows/Windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 7c5498e

Please sign in to comment.