From 4a37bac374b4800b416525df6c79d17bdd48d790 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Mon, 1 May 2023 13:38:04 +0200 Subject: [PATCH] LibCompress: Make LzmaHeader a POD-like type This allows us to initialize the struct using an aggregate initializer. --- Userland/Libraries/LibCompress/Lzma.cpp | 8 ++++---- Userland/Libraries/LibCompress/Lzma.h | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Userland/Libraries/LibCompress/Lzma.cpp b/Userland/Libraries/LibCompress/Lzma.cpp index a95fe3c96b..1dd95e89aa 100644 --- a/Userland/Libraries/LibCompress/Lzma.cpp +++ b/Userland/Libraries/LibCompress/Lzma.cpp @@ -13,10 +13,10 @@ u32 LzmaHeader::dictionary_size() const // "If the value of dictionary size in properties is smaller than (1 << 12), // the LZMA decoder must set the dictionary size variable to (1 << 12)." constexpr u32 minimum_dictionary_size = (1 << 12); - if (m_dictionary_size < minimum_dictionary_size) + if (unchecked_dictionary_size < minimum_dictionary_size) return minimum_dictionary_size; - return m_dictionary_size; + return unchecked_dictionary_size; } Optional LzmaHeader::uncompressed_size() const @@ -24,7 +24,7 @@ Optional LzmaHeader::uncompressed_size() const // We are making a copy of the packed field here because we would otherwise // pass an unaligned reference to the constructor of Optional, which is // undefined behavior. - auto uncompressed_size = m_uncompressed_size; + auto uncompressed_size = encoded_uncompressed_size; // "If "Uncompressed size" field contains ones in all 64 bits, it means that // uncompressed size is unknown and there is the "end marker" in stream, @@ -73,7 +73,7 @@ ErrorOr LzmaHeader::decode_model_properties(u8 input_bits) ErrorOr LzmaHeader::as_decompressor_options() const { - auto model_properties = TRY(decode_model_properties(m_encoded_model_properties)); + auto model_properties = TRY(decode_model_properties(encoded_model_properties)); return Compress::LzmaDecompressorOptions { .literal_context_bits = model_properties.literal_context_bits, diff --git a/Userland/Libraries/LibCompress/Lzma.h b/Userland/Libraries/LibCompress/Lzma.h index 7f71040005..4197a5edaf 100644 --- a/Userland/Libraries/LibCompress/Lzma.h +++ b/Userland/Libraries/LibCompress/Lzma.h @@ -41,10 +41,9 @@ struct [[gnu::packed]] LzmaHeader { static ErrorOr decode_model_properties(u8 input_bits); -private: - u8 m_encoded_model_properties; - u32 m_dictionary_size; - u64 m_uncompressed_size; + u8 encoded_model_properties; + u32 unchecked_dictionary_size; + u64 encoded_uncompressed_size; }; static_assert(sizeof(LzmaHeader) == 13);