[llvm] r195019 - Checking for a return value with FormatMessage; if the call fails, there's no guarantee that the buffer will be non-null.
Aaron Ballman
aaron at aaronballman.com
Mon Nov 18 09:43:22 PST 2013
Author: aaronballman
Date: Mon Nov 18 11:43:22 2013
New Revision: 195019
URL: http://llvm.org/viewvc/llvm-project?rev=195019&view=rev
Log:
Checking for a return value with FormatMessage; if the call fails, there's no guarantee that the buffer will be non-null.
Modified:
llvm/trunk/lib/Support/Windows/Windows.h
Modified: llvm/trunk/lib/Support/Windows/Windows.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Windows.h?rev=195019&r1=195018&r2=195019&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Windows.h (original)
+++ llvm/trunk/lib/Support/Windows/Windows.h Mon Nov 18 11:43:22 2013
@@ -39,11 +39,16 @@ inline bool MakeErrMsg(std::string* ErrM
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>
More information about the llvm-commits
mailing list