mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 23:20:32 +00:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user