mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +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: https://github.com/SerenityOS/serenity/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…
Reference in a new issue