Fixed: FString::ReallocBuffer could write to unallocated memory

- Previously, calling ReallocBuffer with a smaller buffer size than the
  current one could overwrite unallocated memory. This required that the
  string it was called on had more than one reference and therefore
  required creating a new copy. The entire original string would be
  copied, whether it fit in the new buffer or not.
This commit is contained in:
Randy Heit 2015-04-04 18:02:49 -05:00
parent 6da887c34f
commit e451faa1cc

View file

@ -1096,7 +1096,7 @@ void FString::ReallocBuffer (size_t newlen)
{ // If more than one reference, we must use a new copy { // If more than one reference, we must use a new copy
FStringData *old = Data(); FStringData *old = Data();
AllocBuffer (newlen); AllocBuffer (newlen);
StrCopy (Chars, old->Chars(), old->Len); StrCopy (Chars, old->Chars(), newlen < old->Len ? newlen : old->Len);
old->Release(); old->Release();
} }
else else