summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJia Tan <jiat0218@gmail.com>2023-01-11 20:42:29 +0800
committerJia Tan <jiat0218@gmail.com>2023-01-11 20:42:29 +0800
commit25035813d1d596fde692addc33e7f715f1fe55eb (patch)
tree019f142ff2b86b5b6a795ad03140ebd8f6976939 /tests
parent0b8fa310cf56fec55663f62340e49e8e1441594f (diff)
downloadxz-25035813d1d596fde692addc33e7f715f1fe55eb.tar.gz
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_filter_flags.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/tests/test_filter_flags.c b/tests/test_filter_flags.c
index a0916ab..28e75d2 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 = {