diff --git a/common/Error.cpp b/common/Error.cpp index 8ace1f9412..687eaeaebd 100644 --- a/common/Error.cpp +++ b/common/Error.cpp @@ -8,6 +8,7 @@ #include #include +#include #include // Platform-specific includes @@ -108,8 +109,11 @@ void Error::SetWin32(std::string_view prefix, unsigned long err) m_type = Type::Win32; WCHAR buf[128]; - const DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf, + DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf, static_cast(std::size(buf)), nullptr); + while (r > 0 && std::iswspace(buf[r - 1])) + r--; + if (r > 0) { m_description = @@ -143,8 +147,11 @@ void Error::SetHResult(std::string_view prefix, long err) m_type = Type::HResult; WCHAR buf[128]; - const DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf, + DWORD r = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM, nullptr, err, LANG_USER_DEFAULT, buf, static_cast(std::size(buf)), nullptr); + while (r > 0 && std::iswspace(buf[r - 1])) + r--; + if (r > 0) { m_description = fmt::format("{}HRESULT {:08X}: {}", prefix, static_cast(err),