kjn / lbzip2

Parallel bzip2 utility
GNU General Public License v3.0
132 stars 17 forks source link

Align zero-length array to avoid unaligned accesses #25

Open mattst88 opened 5 years ago

mattst88 commented 5 years ago

When make_tree() creates the left-justified base table (uint64_t *B) it does so with 64-bit stores:

B[k] = sofar;

But B points to memory in the zero-length array "uint32_t tt[0]" at the end of struct decoder_state. Since tt's type is uint32_t, it is only aligned to a four byte boundary, and so the 64-bit store in make_tree() causes an unaligned trap on strict platforms like sparc.

mattst88 commented 5 years ago

If/when you take this patch, it would also be nice to make a 2.6 or 3.0 release. There is a ton of improvements since 2.5.