test-strv: avoid unsigned wraparound in backwards iteration

Use pre-decrement starting from 3 instead of post-decrement
starting from 2, so that the unsigned counter does not wrap
past zero on the final iteration.

CID#1548035

Follow-up for 02f19706a9
This commit is contained in:
Luca Boccassi
2026-03-30 09:37:32 +01:00
parent 4f5b28b72c
commit ded2e6e976
+2 -2
View File
@@ -799,14 +799,14 @@ TEST(strv_foreach) {
TEST(strv_foreach_backwards) {
_cleanup_strv_free_ char **a;
unsigned i = 2;
unsigned i = 3;
a = strv_new("one", "two", "three");
assert_se(a);
STRV_FOREACH_BACKWARDS(check, a)
ASSERT_STREQ(*check, input_table_multiple[i--]);
ASSERT_STREQ(*check, input_table_multiple[--i]);
STRV_FOREACH_BACKWARDS(check, (char**) NULL)
assert_not_reached();