]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-path: use usec_add() for timeout calculation
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 7 Apr 2026 23:15:18 +0000 (00:15 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 7 Apr 2026 23:15:18 +0000 (00:15 +0100)
Coverity flags now() + 30 * USEC_PER_SEC as overflowing because
now() can return USEC_INFINITY. Use usec_add() which saturates
on overflow instead of wrapping.

CID#1548025

Follow-up for 331461a5a2ffe323190c4ca6b7bcd35944e36f92

src/test/test-path.c

index 82b1f27ed75506e2e652fefd01a96ad104534342..8b02f5d0fffa4542a999f01b564dfb85ab2587f4 100644 (file)
@@ -78,9 +78,7 @@ static int _check_states(unsigned line,
         assert_se(m);
         assert_se(service);
 
-        /* Silence static analyzers */
-        assert_cc(30 * USEC_PER_SEC <= USEC_INFINITY);
-        usec_t end = now(CLOCK_MONOTONIC) + 30 * USEC_PER_SEC;
+        usec_t end = usec_add(now(CLOCK_MONOTONIC), 30 * USEC_PER_SEC);
 
         while (path->state != path_state || service->state != service_state ||
                path->result != PATH_SUCCESS || service->result != SERVICE_SUCCESS) {