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.