mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-14 02:08:27 +08:00
cmFileLockResult: Avoid allocation for Windows error message
This commit is contained in:

committed by
Brad King

parent
ecadc1495b
commit
efaf987ad1
@@ -5,6 +5,7 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#define WINMSG_BUF_LEN (1024)
|
||||
cmFileLockResult cmFileLockResult::MakeOk()
|
||||
{
|
||||
return cmFileLockResult(OK, 0);
|
||||
@@ -53,18 +54,12 @@ std::string cmFileLockResult::GetOutputMessage() const
|
||||
case SYSTEM:
|
||||
#if defined(_WIN32)
|
||||
{
|
||||
char* errorText = NULL;
|
||||
|
||||
// http://stackoverflow.com/a/455533/2288008
|
||||
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
::FormatMessageA(flags, NULL, this->ErrorValue,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)&errorText, 0, NULL);
|
||||
|
||||
if (errorText != NULL) {
|
||||
const std::string message = errorText;
|
||||
::LocalFree(errorText);
|
||||
char winmsg[WINMSG_BUF_LEN];
|
||||
DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
|
||||
if (FormatMessageA(flags, NULL, this->ErrorValue,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPSTR)winmsg, WINMSG_BUF_LEN, NULL)) {
|
||||
const std::string message = winmsg;
|
||||
return message;
|
||||
} else {
|
||||
return "Internal error (FormatMessageA failed)";
|
||||
|
Reference in New Issue
Block a user