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 0985c7c4e2
This commit is contained in:
Luca Boccassi
2026-03-28 19:49:20 +00:00
parent 1929226e7e
commit be85048e28

View File

@@ -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);