]> granicus.if.org Git - xz/commitdiff
liblzma: Make Valgrind happier with optimized (gcc -O2) liblzma.
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 4 Nov 2015 21:14:00 +0000 (23:14 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 4 Nov 2015 21:14:00 +0000 (23:14 +0200)
When optimizing, GCC can reorder code so that an uninitialized
value gets used in a comparison, which makes Valgrind unhappy.
It doesn't happen when compiled with -O0, which I tend to use
when running Valgrind.

Thanks to Rich Prohaska. I remember this being mentioned long
ago by someone else but nothing was done back then.

src/liblzma/lz/lz_encoder.c

index 48bc487d685371945d8453e3abac05dcf7d9e3fe..5a2be798fd8e9918e3d7c296b98f75871782746f 100644 (file)
@@ -541,7 +541,11 @@ lzma_lz_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
                next->coder->lz.code = NULL;
                next->coder->lz.end = NULL;
 
+               // mf.size is initialized to silence Valgrind
+               // when used on optimized binaries (GCC may reorder
+               // code in a way that Valgrind gets unhappy).
                next->coder->mf.buffer = NULL;
+               next->coder->mf.size = 0;
                next->coder->mf.hash = NULL;
                next->coder->mf.son = NULL;
                next->coder->mf.hash_count = 0;