From b57c0a9db15f04de4b647b15acfe213a1060fc56 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 3 May 2021 21:04:40 +0200 Subject: [PATCH] Fix String::Resize to support buffer growing --- Source/Engine/Core/Types/String.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/Engine/Core/Types/String.h b/Source/Engine/Core/Types/String.h index d8684bf67..d7d42f211 100644 --- a/Source/Engine/Core/Types/String.h +++ b/Source/Engine/Core/Types/String.h @@ -497,18 +497,19 @@ public: } /// - /// Resizes string contents, works like: *this = Left(length) but is faster. + /// Resizes string contents. /// - /// New length of the string (amount of characters from left side to preserve). + /// New length of the string. void Resize(int32 length) { - ASSERT(length >= 0 && length <= _length); + ASSERT(length >= 0); if (_length != length) { const auto oldData = _data; + const auto minLength = _length < length ? _length : length; _length = length; _data = (T*)Platform::Allocate((length + 1) * sizeof(T), 16); - Platform::MemoryCopy(_data, oldData, length * sizeof(T)); + Platform::MemoryCopy(_data, oldData, minLength * sizeof(T)); _data[length] = 0; Platform::Free(oldData); }