diff options
author | Jan Niklas Hasse <jhasse@bixense.com> | 2024-03-16 12:13:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 12:13:59 (GMT) |
commit | 86997c40abca7e882e0902f01af6cd80eb69e3a4 (patch) | |
tree | aa077ef473acfe645daa829369832bbcf037bca2 | |
parent | 3b23631ef750e26b60db27a2b0f2333fb7e80714 (diff) | |
parent | df4c6a461ef29b1a7e7be9d50453ef7a3b38e6f3 (diff) | |
download | Ninja-86997c40abca7e882e0902f01af6cd80eb69e3a4.zip Ninja-86997c40abca7e882e0902f01af6cd80eb69e3a4.tar.gz Ninja-86997c40abca7e882e0902f01af6cd80eb69e3a4.tar.bz2 |
Merge pull request #2394 from jheydebrand/GetLastErrorString-crash
Fix crash when FormatMessageA sets lpBuffer to nullptr
-rw-r--r-- | src/util.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc index 5f67fcf..2a43775 100644 --- a/src/util.cc +++ b/src/util.cc @@ -540,6 +540,13 @@ string GetLastErrorString() { (char*)&msg_buf, 0, NULL); + + if (msg_buf == nullptr) { + char fallback_msg[128] = {0}; + snprintf(fallback_msg, sizeof(fallback_msg), "GetLastError() = %d", err); + return fallback_msg; + } + string msg = msg_buf; LocalFree(msg_buf); return msg; |