From e665714341da914a05d79a92d3e6d664b4e1aff8 Mon Sep 17 00:00:00 2001 From: Reece Date: Thu, 26 May 2022 15:02:23 +0100 Subject: [PATCH] [*] Bug fix: NT registry read function conflated array length with count [*] Locale convert wchar -> utf count was not respected under non-nt targets --- Source/Locale/Locale.cpp | 2 +- Source/SWInfo/SWInfo.NT.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/Locale/Locale.cpp b/Source/Locale/Locale.cpp index e1b9bc09..eb514101 100644 --- a/Source/Locale/Locale.cpp +++ b/Source/Locale/Locale.cpp @@ -60,7 +60,7 @@ namespace Aurora::Locale WideCharToMultiByte(CP_UTF8, 0, in, length, ret.data(), ret.size(), NULL, NULL); return ret; #elif !defined(AU_NO_CPPLOCALE) - return gUtf8Conv.to_bytes(std::wstring(in, wcslen(in))); + return gUtf8Conv.to_bytes(std::wstring(in, wcsnlen(in, length))); #else SysPushErrorUnimplemented("ConvertFromWChar"); return {}; diff --git a/Source/SWInfo/SWInfo.NT.cpp b/Source/SWInfo/SWInfo.NT.cpp index 6e2632f8..39236c20 100644 --- a/Source/SWInfo/SWInfo.NT.cpp +++ b/Source/SWInfo/SWInfo.NT.cpp @@ -43,7 +43,7 @@ namespace Aurora::SWInfo std::wstring in; - if (!AuTryResize(in, dwBufferSize)) + if (!AuTryResize(in, dwBufferSize / sizeof(wchar_t))) { SysPushErrorMem(); return false; @@ -55,7 +55,10 @@ namespace Aurora::SWInfo return false; } - strValue = Locale::ConvertFromWChar(in.data(), in.size()); + auto c = dwBufferSize / sizeof(wchar_t); + if (c) c--; + + strValue = Locale::ConvertFromWChar(in.data(), c); return strValue.size(); }