mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
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:
parent
9d70f0383f
commit
3843b8c0a1
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue