From 69124fda961df4d2fcf6d8055e46b5a5c3732c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 15 Jan 2024 10:43:49 +0100 Subject: [PATCH] Fix up a small mistake in ConvertUTF8ToWString --- Common/Data/Encoding/Utf8.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Common/Data/Encoding/Utf8.cpp b/Common/Data/Encoding/Utf8.cpp index 155ddc607e..6da1e0e054 100644 --- a/Common/Data/Encoding/Utf8.cpp +++ b/Common/Data/Encoding/Utf8.cpp @@ -572,11 +572,10 @@ static size_t ConvertUTF8ToWStringInternal(wchar_t *dest, size_t destSize, std:: std::wstring ConvertUTF8ToWString(std::string_view source) { std::wstring dst; - // utf-8 won't be less bytes than there are characters. - dst.resize(source.size(), 0); + // conservative size estimate for wide characters from utf-8 bytes. Will always reserve too much space. + dst.resize(source.size()); size_t realLen = ConvertUTF8ToWStringInternal(&dst[0], source.size(), source); - dst.resize(realLen); - dst[realLen] = 0; + dst.resize(realLen); // no need to write a NUL, it's done for us by resize. return dst; }