]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
liblzma: Initialize lzma_lz_encoder pointers with NULL.
authorJia Tan <jiat0218@gmail.com>
Wed, 20 Dec 2023 13:31:34 +0000 (21:31 +0800)
committerJia Tan <jiat0218@gmail.com>
Wed, 20 Dec 2023 13:38:39 +0000 (21:38 +0800)
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.

src/liblzma/lz/lz_encoder.c

index dbc5c7b8ba560ba4a67b13e48c645a01fee8fec1..c45e193e4150d81cbedaee41cb7baad29cea4285 100644 (file)
@@ -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