From 1a03f45a7344781d63e39bbf58aef3c3ab69fbdf Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 15 Mar 2023 11:23:37 +0100 Subject: [PATCH] LibGfx: Remove reckless PNGChunk::add(T) method This method added function using host byte order, which is never what we want. In practice, it was fine because it was only called from add_u8() (which is just 1 byte large) and add_as_big_endian() (since that did endian swapping before calling the method). But the method doesn't really help any and is dangerous, so remove it. No behavior change. --- Userland/Libraries/LibGfx/PNGWriter.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibGfx/PNGWriter.cpp b/Userland/Libraries/LibGfx/PNGWriter.cpp index 07f34076d9..d074f4503f 100644 --- a/Userland/Libraries/LibGfx/PNGWriter.cpp +++ b/Userland/Libraries/LibGfx/PNGWriter.cpp @@ -41,9 +41,6 @@ public: u32 crc(); private: - template - ErrorOr add(T); - ByteBuffer m_data; DeprecatedString m_type; }; @@ -52,7 +49,7 @@ PNGChunk::PNGChunk(DeprecatedString type) : m_type(move(type)) { // NOTE: These are MUST() because they should always be able to fit in m_data's inline capacity. - MUST(add(0)); + MUST(add_as_big_endian(0)); MUST(store_type()); } @@ -74,13 +71,6 @@ u32 PNGChunk::crc() return crc; } -template -ErrorOr PNGChunk::add(T data) -{ - TRY(m_data.try_append(&data, sizeof(T))); - return {}; -} - ErrorOr PNGChunk::compress_and_add(ReadonlyBytes uncompressed_bytes) { return add(TRY(Compress::ZlibCompressor::compress_all(uncompressed_bytes, Compress::ZlibCompressionLevel::Best))); @@ -96,13 +86,13 @@ template ErrorOr PNGChunk::add_as_big_endian(T data) { auto data_out = AK::convert_between_host_and_big_endian(data); - TRY(add(data_out)); + TRY(m_data.try_append(&data_out, sizeof(T))); return {}; } ErrorOr PNGChunk::add_u8(u8 data) { - TRY(add(data)); + TRY(m_data.try_append(data)); return {}; }