Skip to content

Commit

Permalink
liblzma: Initialize lzma_lz_encoder pointers with NULL.
Browse files Browse the repository at this point in the history
This fixes the recent change to lzma_lz_encoder that used memzero
instead of the NULL constant. On some compilers the NULL constant
(always 0) may not equal the NULL pointer (this only needs to guarentee
to not point to valid memory address).

Later code compares the pointers to the NULL pointer so we must
initialize them with the NULL pointer instead of 0 to guarentee
code correctness.
  • Loading branch information
JiaT75 committed Dec 20, 2023
1 parent 183a62f commit b34b6a9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/liblzma/lz/lz_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,11 @@ lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
next->update = &lz_encoder_update;
next->set_out_limit = &lz_encoder_set_out_limit;

memzero((&coder->lz), sizeof(lzma_lz_encoder));
coder->lz.coder = NULL;
coder->lz.code = NULL;
coder->lz.end = NULL;
coder->lz.options_update = NULL;
coder->lz.set_out_limit = NULL;

// mf.size is initialized to silence Valgrind
// when used on optimized binaries (GCC may reorder
Expand Down

0 comments on commit b34b6a9

Please sign in to comment.