From a12840b2412baf651413ff46a0ec39b5527db3b1 Mon Sep 17 00:00:00 2001 From: killua Date: Mon, 16 Mar 2026 18:04:40 +0400 Subject: [PATCH] fix: null terminator --- src/source/parser/platform_parsers/windows_parser.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/source/parser/platform_parsers/windows_parser.cpp b/src/source/parser/platform_parsers/windows_parser.cpp index c8cbf83..a44eca2 100644 --- a/src/source/parser/platform_parsers/windows_parser.cpp +++ b/src/source/parser/platform_parsers/windows_parser.cpp @@ -42,15 +42,16 @@ std::string utf8_from_wstring(const std::wstring &w) { if (w.empty()) return {}; - int needed = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w.c_str(), -1, nullptr, 0, nullptr, nullptr); + int needed = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w.data(), static_cast(w.size()), nullptr, 0, + nullptr, nullptr); if (needed <= 0) { throw std::runtime_error("WideCharToMultiByte sizing failed ("s + windows_error_message(::GetLastError()) + ")"); } std::string out; out.resize(needed); - int written = - ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w.c_str(), -1, out.data(), out.size(), nullptr, nullptr); + int written = ::WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, w.data(), static_cast(w.size()), out.data(), + needed, nullptr, nullptr); if (written <= 0) { throw std::runtime_error( "WideCharToMultiByte convert failed, Error("s + windows_error_message(::GetLastError()) + ")" +