From 0b0ad41ddbc7e881e0645de4c235642cbc22a107 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 28 Sep 2019 21:19:11 -0500 Subject: [PATCH] fix wchar_t buffer uneven allocate memory --- src/common/util/strConverter.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/util/strConverter.hpp b/src/common/util/strConverter.hpp index f9511e690..b75a292d4 100644 --- a/src/common/util/strConverter.hpp +++ b/src/common/util/strConverter.hpp @@ -41,7 +41,7 @@ static std::wstring utf8_to_utf16(const char* utf8_string) // Depending on what type of UTF-16 string is input, otherwise will use native by default. static std::string utf16_to_ascii(const wchar_t* utf16_string) { - char* tempASCII = SDL_iconv_string(/*to:*/"ASCII", /*from:*/"UTF-16", reinterpret_cast(utf16_string), wcslen(utf16_string)*2 + 1); + char* tempASCII = SDL_iconv_string(/*to:*/"ASCII", /*from:*/"UTF-16", reinterpret_cast(utf16_string), wcslen(utf16_string)*2 + 2); const std::string strASCII = tempASCII; // Don't forget to free allocated string from SDL library. SDL_free(tempASCII); @@ -52,7 +52,7 @@ static std::string utf16_to_ascii(const wchar_t* utf16_string) // Enforce to expect little endian UTF-16 string is input. static std::string utf16le_to_ascii(const wchar_t* utf16le_string) { - char* tempASCII = SDL_iconv_string(/*to:*/"ASCII", /*from:*/"UTF-16LE", reinterpret_cast(utf16le_string), wcslen(utf16le_string)*2 + 1); + char* tempASCII = SDL_iconv_string(/*to:*/"ASCII", /*from:*/"UTF-16LE", reinterpret_cast(utf16le_string), wcslen(utf16le_string)*2 + 2); const std::string strASCII = tempASCII; // Don't forget to free allocated string from SDL library. SDL_free(tempASCII);