From cf2833fdc137f6388138067c62fdf29d6cbf18b6 Mon Sep 17 00:00:00 2001 From: Andre Maroneze Date: Tue, 25 May 2021 15:23:35 +0200 Subject: [PATCH] avoid use of uninitialized value in tdefl_record_literal In tdefl_record_literal, the following expression may read an uninitialized value in the m_pLZ_flags field: *d->m_pLZ_flags = (mz_uint8)(*d->m_pLZ_flags >> 1); By explicitly initializing it, we avoid possible undefined behaviors. Issue found with Frama-C. --- miniz_tdef.c | 1 + 1 file changed, 1 insertion(+) diff --git a/miniz_tdef.c b/miniz_tdef.c index 64113f8..4eb8e07 100644 --- a/miniz_tdef.c +++ b/miniz_tdef.c @@ -1333,6 +1333,7 @@ tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_fun d->m_output_flush_ofs = d->m_output_flush_remaining = d->m_finished = d->m_block_index = d->m_bit_buffer = d->m_wants_to_finish = 0; d->m_pLZ_code_buf = d->m_lz_code_buf + 1; d->m_pLZ_flags = d->m_lz_code_buf; + *d->m_pLZ_flags = 0; d->m_num_flags_left = 8; d->m_pOutput_buf = d->m_output_buf; d->m_pOutput_buf_end = d->m_output_buf;