From 18b7ddd0b5ead195d0d57e171526df02fb47ce9f Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Mon, 3 Jul 2023 13:33:25 -0400 Subject: [PATCH] AK: Rename the `const` overload of `FixedMemoryStream::bytes()` Due to overload resolutions rules, this simple code provokes a crash: ReadonlyBytes readonly_bytes{}; FixedMemoryStream stream{readonly_bytes}; ReadonlyBytes give_them_back{stream.bytes()}; // -> Panics on VERIFY(m_writing_enabled); // but this is fine: auto bytes = static_cast(*stream).bytes() If we need to be explicit about it, let's rename the overload instead of adding that `static_cast`. --- AK/MemoryStream.cpp | 2 +- AK/MemoryStream.h | 2 +- Userland/Libraries/LibVideo/VP9/Context.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AK/MemoryStream.cpp b/AK/MemoryStream.cpp index a5c8fc1985f..0a04962580e 100644 --- a/AK/MemoryStream.cpp +++ b/AK/MemoryStream.cpp @@ -114,7 +114,7 @@ Bytes FixedMemoryStream::bytes() VERIFY(m_writing_enabled); return m_bytes; } -ReadonlyBytes FixedMemoryStream::bytes() const +ReadonlyBytes FixedMemoryStream::readonly_bytes() const { return m_bytes; } diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index 7a9ce7d8ec6..84d5a5a58a2 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -32,7 +32,7 @@ public: virtual ErrorOr write_until_depleted(ReadonlyBytes bytes) override; Bytes bytes(); - ReadonlyBytes bytes() const; + ReadonlyBytes readonly_bytes() const; size_t offset() const; size_t remaining() const; diff --git a/Userland/Libraries/LibVideo/VP9/Context.h b/Userland/Libraries/LibVideo/VP9/Context.h index 890a5654ceb..58bcf5bae5e 100644 --- a/Userland/Libraries/LibVideo/VP9/Context.h +++ b/Userland/Libraries/LibVideo/VP9/Context.h @@ -59,7 +59,7 @@ public: DecoderErrorOr create_range_decoder(size_t size) { - ReadonlyBytes stream_data = static_cast(*stream).bytes(); + ReadonlyBytes stream_data = stream->readonly_bytes(); auto compressed_header_data = ReadonlyBytes(stream_data.data() + stream->offset(), size); // 9.2.1: The Boolean decoding process specified in section 9.2.2 is invoked to read a marker syntax element from the