1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

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.
This commit is contained in:
Jia Tan 2023-01-11 20:42:29 +08:00
parent 0b8fa310cf
commit 25035813d1

View file

@ -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 = {