From: Luca Boccassi Date: Sat, 28 Mar 2026 19:49:20 +0000 (+0000) Subject: cpu-set-util: add asserts to guide static analysis after realloc X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=be85048e280bd99ffe0e4ed8ea8695a2faf4f1ed;p=thirdparty%2Fsystemd.git cpu-set-util: add asserts to guide static analysis after realloc Coverity flags CPU_SET_S() calls as potential out-of-bounds writes because it cannot trace that cpu_set_realloc() guarantees the allocated buffer is large enough for the given index. Add asserts to make the size invariant explicit. CID#1611787 CID#1611788 Follow-up for 0985c7c4e22c8dbbea4398cf3453da45ebf63800 --- diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c index e4ef36da9aa..9211dbe47e5 100644 --- a/src/shared/cpu-set-util.c +++ b/src/shared/cpu-set-util.c @@ -159,6 +159,8 @@ int cpu_set_add(CPUSet *c, size_t i) { if (r < 0) return r; + /* Silence static analyzers */ + assert(i / CHAR_BIT < c->allocated); CPU_SET_S(i, c->allocated, c->set); return 0; } @@ -194,6 +196,8 @@ int cpu_set_add_range(CPUSet *c, size_t start, size_t end) { if (r < 0) return r; + /* Silence static analyzers */ + assert(end / CHAR_BIT < c->allocated); for (size_t i = start; i <= end; i++) CPU_SET_S(i, c->allocated, c->set);