mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +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
1 changed files with 3 additions and 2 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue