From 9b541f29488f5f59cb1dd6edb54c91697e4d5172 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 14 Oct 2022 15:44:57 +0200 Subject: [PATCH] Fix buffer size for wchar-multibyte conversion --- include/irrString.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/irrString.h b/include/irrString.h index f454aed4..d8757af8 100644 --- a/include/irrString.h +++ b/include/irrString.h @@ -1503,12 +1503,12 @@ static size_t wStringToMultibyte(string& destination, const wchar_t* source, { if ( sourceSize ) { - destination.reserve(sourceSize+1); + destination.reserve(sizeof(wchar_t)*sourceSize+1); #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. Consider using wcstombs_s instead. #endif - const size_t written = wcstombs(destination.array, source, (size_t)sourceSize); + const size_t written = wcstombs(destination.array, source, destination.allocated-1); #if defined(_MSC_VER) #pragma warning(pop) #endif