diff --git a/include/Void/System/Path.hpp b/include/Void/System/Path.hpp index 9fcfedc..dc68e10 100644 --- a/include/Void/System/Path.hpp +++ b/include/Void/System/Path.hpp @@ -209,22 +209,18 @@ private: [[nodiscard]] inline std::string win32_message(DWORD error) { - char* buffer = nullptr; + std::array buffer{}; const DWORD length = ::FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - reinterpret_cast(&buffer), - 0, + buffer.data(), + static_cast(buffer.size()), nullptr); - std::string message = (length != 0 && buffer != nullptr) - ? std::string{buffer, length} + std::string message = length != 0 + ? std::string{buffer.data(), length} : std::string{"unknown error"}; - if (buffer != nullptr) { - ::LocalFree(buffer); - } while (!message.empty() && (message.back() == '\n' || message.back() == '\r' || message.back() == ' ' || message.back() == '.')) {