From 069ceab9c531dafb1fcb3259b6ec813b2710fc3a Mon Sep 17 00:00:00 2001 From: zhangyuan29 Date: Wed, 30 Apr 2025 14:39:41 +0800 Subject: [PATCH] lzf: prevent lzf header struct optimization Add packed attribute to lzf header structs to prevent the compiler from optimizing lzf_magic array initialization into wider store instructions (e.g. st.h), which can cause misaligned access exceptions on architectures that do not support unaligned memory access. Signed-off-by: zhangyuan29 --- include/lzf.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/lzf.h b/include/lzf.h index 81ba13762c8..42cd26ca693 100644 --- a/include/lzf.h +++ b/include/lzf.h @@ -64,26 +64,26 @@ /* LZF headers */ -struct lzf_header_s /* Common data header */ +begin_packed_struct struct lzf_header_s /* Common data header */ { uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */ uint8_t lzf_type; /* LZF_TYPE0_HDR or LZF_TYPE1_HDR */ -}; +} end_packed_struct; -struct lzf_type0_header_s /* Uncompressed data header */ +begin_packed_struct struct lzf_type0_header_s /* Uncompressed data header */ { uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */ uint8_t lzf_type; /* LZF_TYPE0_HDR */ uint8_t lzf_len[2]; /* Data length (big-endian) */ -}; +} end_packed_struct; -struct lzf_type1_header_s /* Compressed data header */ +begin_packed_struct struct lzf_type1_header_s /* Compressed data header */ { uint8_t lzf_magic[2]; /* [0]='Z', [1]='V' */ uint8_t lzf_type; /* LZF_TYPE1_HDR */ uint8_t lzf_clen[2]; /* Compressed data length (big-endian) */ uint8_t lzf_ulen[2]; /* Uncompressed data length (big-endian) */ -}; +} end_packed_struct; /* LZF hash table */