]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
uid-range: add assert to silence coverity
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 7 Apr 2026 22:45:30 +0000 (23:45 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 7 Apr 2026 22:45:39 +0000 (23:45 +0100)
Coverity flags range->n_entries - j - 1 and j-- as potential
underflows. Add an assert that j > 0 before decrementing, since
j starts at i + 1 >= 1 and is never decremented below its
initial value.

CID#1548015

Follow-up for 8dcc66cefc8ab489568c737adcba960756d76a3c

src/basic/uid-range.c

index 628710a8709bcc7272ffc697a113d03d3d35ba48..3d8f8445c45599120bd26a0087be96df91c104b0 100644 (file)
@@ -76,6 +76,9 @@ static void uid_range_coalesce(UIDRange *range) {
                                 memmove(y, y + 1, sizeof(UIDRangeEntry) * (range->n_entries - j - 1));
 
                         range->n_entries--;
+
+                        /* Silence static analyzers, j cannot be 0 here since it starts at i + 1, i.e. >= 1 */
+                        assert(j > 0);
                         j--;
                 }
         }