diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-11-18 17:43:22 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-11-18 17:43:22 +0000 |
commit | 7c5498ee55e241dea91cca022bd9a5831a1ba4b1 (patch) | |
tree | 776960f0016ac70dfc717af9b5e8ada85d05d16e /lib | |
parent | eae6e546ec5339179b4c7401416fbf2d641a9e90 (diff) | |
download | external_llvm-7c5498ee55e241dea91cca022bd9a5831a1ba4b1.zip external_llvm-7c5498ee55e241dea91cca022bd9a5831a1ba4b1.tar.gz external_llvm-7c5498ee55e241dea91cca022bd9a5831a1ba4b1.tar.bz2 |
Checking for a return value with FormatMessage; if the call fails, there'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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/Windows/Windows.h | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/Support/Windows/Windows.h b/lib/Support/Windows/Windows.h index 657ae4f..1f3417d 100644 --- a/lib/Support/Windows/Windows.h +++ b/lib/Support/Windows/Windows.h @@ -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> |