AK: Perform a resize in ByteBuffer::get_bytes_for_writing()

ByteBuffer::get_bytes_for_writing() was only ensuring capacity before
this patch. The method needs to call resize to register the appended
data, otherwise it will be overwritten with next data addition.
This commit is contained in:
Lucas CHOLLET 2022-02-27 23:16:50 +01:00 committed by Linus Groh
parent 9d70f0383f
commit 3843b8c0a1

View file

@ -183,8 +183,9 @@ public:
/// Ensures that the required space is available.
ErrorOr<Bytes> get_bytes_for_writing(size_t length)
{
TRY(try_ensure_capacity(size() + length));
return Bytes { data() + size(), length };
auto const old_size = size();
TRY(try_resize(old_size + length));
return Bytes { data() + old_size, length };
}
/// Like get_bytes_for_writing, but crashes if allocation fails.