zyfeier opened a new pull request, #18387: URL: https://github.com/apache/nuttx/pull/18387
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. *Note: Please adhere to [Contributing Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).* ## Summary Add begin_packed_struct/end_packed_struct attributes to the three LZF header structs (lzf_header_s, lzf_type0_header_s, lzf_type1_header_s) in lzf.h. Without packed attributes, the compiler may optimize the lzf_magic[2] array initialization into a wider store instruction (e.g. st.h), causing misaligned access exceptions on architectures that do not support unaligned memory access. ## Impact - Fixes misaligned access exceptions on strict-alignment architectures - No functional change on architectures that support unaligned access - No breaking changes ## Testing Build & runtime verification on sim:nsh with CONFIG_LIBC_LZF=y and CONFIG_SYSTEM_LZF=y. Test 1 — Text data compress/decompress: ``` nsh> echo ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 > /tmp/testdata nsh> lzf -cv /tmp/testdata /tmp/testdata: -- replaced with /tmp/testdata.lzf nsh> lzf -dv /tmp/testdata.lzf /tmp/testdata.lzf: -- replaced with /tmp/testdata nsh> cat /tmp/testdata ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ``` Result: PASS — decompressed content matches original. Test 2 — Binary data (4KB zeros) compress/decompress: ``` nsh> dd if=/dev/zero of=/tmp/zeros bs=1024 count=4 4096 bytes (4 blocks) copied nsh> lzf -cv /tmp/zeros /tmp/zeros: -- replaced with /tmp/zeros.lzf nsh> lzf -dv /tmp/zeros.lzf /tmp/zeros.lzf: -- replaced with /tmp/zeros nsh> dd if=/tmp/zeros of=/dev/null bs=1024 4096 bytes (4 blocks) copied ``` Result: PASS — decompressed size matches original (4096 bytes). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
