]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-strv: avoid unsigned wraparound in backwards iteration
authorLuca Boccassi <luca.boccassi@gmail.com>
Sat, 28 Mar 2026 21:47:08 +0000 (21:47 +0000)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 30 Mar 2026 08:37:32 +0000 (09:37 +0100)
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 02f19706a9fd96e05c9ed16aa55ba3d03d008167

src/test/test-strv.c

index b3468b1cfac62e0b3ea369050079540faf863d2e..283ae5c865aceb3c72462b65ea00daa5f6bb9047 100644 (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();