mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +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
Notes:
sideshowbarker
2024-07-17 18:23:22 +09:00
Author: https://github.com/LucasChollet
Commit: 3843b8c0a1
Pull-request: https://github.com/SerenityOS/serenity/pull/13870
Issue: https://github.com/SerenityOS/serenity/issues/5259
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/linusg
Reviewed-by: https://github.com/petelliott
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