If ncpus is not checked against the value 0, subsequent macros
CPU_ALLOC_SIZE and cpuset_nbits() will return garbage (0), which
can cause issues when memory has to be allocated or initialized
in callers where the size is assumed to be > 0. So let us return
NULL for 0 ncpus.
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
*/
cpu_set_t *cpuset_alloc(int ncpus, size_t *setsize, size_t *nbits)
{
- cpu_set_t *set = CPU_ALLOC(ncpus);
+ cpu_set_t *set = NULL;
+ if (ncpus)
+ set = CPU_ALLOC(ncpus);
if (!set)
return NULL;
if (setsize)