summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows/Windows.h
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2013-11-18 17:43:22 +0000
committerAaron Ballman <aaron@aaronballman.com>2013-11-18 17:43:22 +0000
commit69c55edb18ab9cf85ab1cfae426637f9fcfbae2a (patch)
tree75ec14d318c1e079d89feb218e7c5150b35af70a /llvm/lib/Support/Windows/Windows.h
parent5de2378f7ea44d3a3d9488d37d63cd12b0b8e8b0 (diff)
downloadbcm5719-llvm-69c55edb18ab9cf85ab1cfae426637f9fcfbae2a.tar.gz
bcm5719-llvm-69c55edb18ab9cf85ab1cfae426637f9fcfbae2a.zip
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
Diffstat (limited to 'llvm/lib/Support/Windows/Windows.h')
-rw-r--r--llvm/lib/Support/Windows/Windows.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Support/Windows/Windows.h b/llvm/lib/Support/Windows/Windows.h
index 657ae4fc838..1f3417d160a 100644
--- a/llvm/lib/Support/Windows/Windows.h
+++ b/llvm/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>
OpenPOWER on IntegriCloud