From 5f18cf75c5d660873f840512f2fe55d4e239e238 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 31 May 2021 00:31:46 +0200 Subject: AK: Replace ByteBuffer::grow with resize()/ensure_capacity() Previously ByteBuffer::grow() behaved like Vector::resize(). However the function name was somewhat ambiguous - and so this patch updates ByteBuffer to behave more like Vector by replacing grow() with resize() and adding an ensure_capacity() method. This also lets the user change the buffer's capacity without affecting the size which was not previously possible. Additionally this patch makes the capacity() method public (again). --- Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp | 3 +-- Userland/Libraries/LibTLS/HandshakeClient.cpp | 3 +-- Userland/Libraries/LibTLS/TLSPacketBuilder.h | 2 +- Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) (limited to 'Userland/Libraries') diff --git a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp index a4beb68e45..11c68e1538 100644 --- a/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp +++ b/Userland/Libraries/LibCrypto/NumberTheory/ModularFunctions.cpp @@ -165,8 +165,7 @@ UnsignedBigInteger random_number(const UnsignedBigInteger& min, const UnsignedBi UnsignedBigInteger base; auto size = range.trimmed_length() * sizeof(u32) + 2; // "+2" is intentional (see below). - ByteBuffer buffer; - buffer.grow(size); + auto buffer = ByteBuffer::create_uninitialized(size); auto* buf = buffer.data(); fill_with_random(buf, size); diff --git a/Userland/Libraries/LibTLS/HandshakeClient.cpp b/Userland/Libraries/LibTLS/HandshakeClient.cpp index 949121c891..55521d658b 100644 --- a/Userland/Libraries/LibTLS/HandshakeClient.cpp +++ b/Userland/Libraries/LibTLS/HandshakeClient.cpp @@ -117,8 +117,7 @@ bool TLSv12::compute_master_secret_from_pre_master_secret(size_t length) return false; } - m_context.master_key.clear(); - m_context.master_key.grow(length); + m_context.master_key.resize(length); pseudorandom_function( m_context.master_key, diff --git a/Userland/Libraries/LibTLS/TLSPacketBuilder.h b/Userland/Libraries/LibTLS/TLSPacketBuilder.h index dfc6cf7394..955caa0492 100644 --- a/Userland/Libraries/LibTLS/TLSPacketBuilder.h +++ b/Userland/Libraries/LibTLS/TLSPacketBuilder.h @@ -75,7 +75,7 @@ public: m_current_length += bytes; if (m_packet_data.size() < m_current_length) { - m_packet_data.grow(m_current_length); + m_packet_data.resize(m_current_length); } m_packet_data.overwrite(old_length, data, bytes); diff --git a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h index 4646df4738..98db12d9ab 100644 --- a/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h +++ b/Userland/Libraries/LibWasm/AbstractMachine/AbstractMachine.h @@ -332,7 +332,7 @@ public: if (m_type.limits().max().value_or(new_size) < new_size) return false; auto previous_size = m_size; - m_data.grow(new_size); + m_data.resize(new_size); m_size = new_size; // The spec requires that we zero out everything on grow __builtin_memset(m_data.offset_pointer(previous_size), 0, size_to_grow); -- cgit v1.2.3