size_t i;
int ret = -1;
+ /* Okay, @func should never return NULL here because it does
+ * so iff corresponding resource does not exists. But if it
+ * doesn't we should not have been called in the first place.
+ * But some compilers fails to see this complex reasoning and
+ * deduct that this code is buggy. Shut them up by checking
+ * for return value of sched. Even though we don't need to.
+ */
+
if (!(schedMap = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN)) ||
!(prioMap = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN)))
goto cleanup;
while ((next = virBitmapNextSetBit(resourceMap, next)) > -1) {
sched = func(def, next);
- if (sched->policy == i)
+ if (sched && sched->policy == i)
ignore_value(virBitmapSetBit(schedMap, next));
}
/* we need to find a subset of vCPUs with the given scheduler
* that share the priority */
nextprio = virBitmapNextSetBit(schedMap, -1);
- sched = func(def, nextprio);
- priority = sched->priority;
+ if (!(sched = func(def, nextprio)))
+ goto cleanup;
+ priority = sched->priority;
ignore_value(virBitmapSetBit(prioMap, nextprio));
while ((nextprio = virBitmapNextSetBit(schedMap, nextprio)) > -1) {
sched = func(def, nextprio);
- if (sched->priority == priority)
+ if (sched && sched->priority == priority)
ignore_value(virBitmapSetBit(prioMap, nextprio));
}