From: Luca Boccassi Date: Sat, 28 Mar 2026 21:47:08 +0000 (+0000) Subject: test-strv: avoid unsigned wraparound in backwards iteration X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ded2e6e9761ef0838c6913f7acd21e6bf2f05075;p=thirdparty%2Fsystemd.git 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 02f19706a9fd96e05c9ed16aa55ba3d03d008167 --- diff --git a/src/test/test-strv.c b/src/test/test-strv.c index b3468b1cfac..283ae5c865a 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -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();