Fix buffer size for wchar-multibyte conversion

This commit is contained in:
sfan5 2022-10-14 15:44:57 +02:00
parent 1cf0f3bef0
commit 9b541f2948

@ -1503,12 +1503,12 @@ static size_t wStringToMultibyte(string<c8>& destination, const wchar_t* source,
{ {
if ( sourceSize ) if ( sourceSize )
{ {
destination.reserve(sourceSize+1); destination.reserve(sizeof(wchar_t)*sourceSize+1);
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. Consider using wcstombs_s instead. #pragma warning(disable: 4996) // 'wcstombs': This function or variable may be unsafe. Consider using wcstombs_s instead.
#endif #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) #if defined(_MSC_VER)
#pragma warning(pop) #pragma warning(pop)
#endif #endif