From 25035813d1d596fde692addc33e7f715f1fe55eb Mon Sep 17 00:00:00 2001 From: Jia Tan Date: Wed, 11 Jan 2023 20:42:29 +0800 Subject: [PATCH] Tests: Fix type-limits warning in test_filter_flags. This only occurs in test_filter_flags when the BCJ filters are not configured and built. In this case, ARRAY_SIZE() returns 0 and causes a type-limits warning with the loop variable since an unsigned number will always be >= 0. --- tests/test_filter_flags.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_filter_flags.c b/tests/test_filter_flags.c index a0916ab9..28e75d2f 100644 --- a/tests/test_filter_flags.c +++ b/tests/test_filter_flags.c @@ -104,7 +104,12 @@ test_lzma_filter_flags_size(void) assert_true(size != 0 && size < LZMA_BLOCK_HEADER_SIZE_MAX); } - for (uint32_t i = 0; i < ARRAY_SIZE(bcj_filters_encoders); i++) { + // Do not use macro ARRAY_SIZE() in the for loop condition directly. + // If the BCJ filters are not configured and built, then ARRAY_SIZE() + // will return 0 and cause a warning because the for loop will never + // execute since any unsigned number cannot be < 0 (-Werror=type-limits). + const uint32_t bcj_array_size = ARRAY_SIZE(bcj_filters_decoders); + for (uint32_t i = 0; i < bcj_array_size; i++) { assert_lzma_ret(lzma_filter_flags_size(&size, &bcj_filters_encoders[i]), LZMA_OK); assert_true(size != 0 && size < LZMA_BLOCK_HEADER_SIZE_MAX); @@ -215,7 +220,8 @@ test_lzma_filter_flags_encode(void) .start_offset = 257 }; - for (uint32_t i = 0; i < ARRAY_SIZE(bcj_filters_encoders); i++) { + const uint32_t bcj_array_size = ARRAY_SIZE(bcj_filters_decoders); + for (uint32_t i = 0; i < bcj_array_size; i++) { // NULL options should pass for bcj filters verify_filter_flags_encode(&bcj_filters_encoders[i], true); lzma_filter bcj_with_options = { @@ -377,7 +383,8 @@ test_lzma_filter_flags_decode(void) free(decoded); } - for (uint32_t i = 0; i < ARRAY_SIZE(bcj_filters_decoders); i++) { + const uint32_t bcj_array_size = ARRAY_SIZE(bcj_filters_decoders); + for (uint32_t i = 0; i < bcj_array_size; i++) { if (lzma_filter_encoder_is_supported( bcj_filters_decoders[i].id)) { lzma_filter bcj_decoded = {