From 3843b8c0a14a1131911032dc78098eb2e3e826b0 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sun, 27 Feb 2022 23:16:50 +0100 Subject: [PATCH] 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. --- AK/ByteBuffer.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h index 513c505ce1..d8e5848b88 100644 --- a/AK/ByteBuffer.h +++ b/AK/ByteBuffer.h @@ -183,8 +183,9 @@ public: /// Ensures that the required space is available. ErrorOr 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.