mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
hypervisor: Revisit Coverity issues regarding cpumap
Turns out the issue regarding ptr_arith and sign_exension weren't false positives. When shifting an 'unsigned char' as a target, it gets promoted to an 'int'; however, that 'int' cannot be shifted 32 bits which was how the algorithm was written. For the ptr_arith rather than index into the cpumap, change the to address as necessary and assign directly.
This commit is contained in:
parent
cbdf3b7c97
commit
c059cdeaf3
@ -1773,17 +1773,17 @@ virXen_setvcpumap(int handle,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
} else {
|
} else {
|
||||||
cpumap_t xen_cpumap; /* limited to 64 CPUs in old hypervisors */
|
cpumap_t xen_cpumap; /* limited to 64 CPUs in old hypervisors */
|
||||||
uint64_t *pm = &xen_cpumap;
|
uint64_t *pm;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
if ((maplen > (int)sizeof(cpumap_t)) || (sizeof(cpumap_t) & 7))
|
if ((maplen > (int)sizeof(cpumap_t)) || (sizeof(cpumap_t) & 7))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
memset(pm, 0, sizeof(cpumap_t));
|
memset(&xen_cpumap, 0, sizeof(cpumap_t));
|
||||||
for (j = 0; j < maplen; j++) {
|
for (j = 0; j < maplen; j++) {
|
||||||
/* coverity[ptr_arith] */
|
if ((j & 7) == 0)
|
||||||
/* coverity[sign_extension] */
|
pm = (uint64_t *)((uint64_t)&xen_cpumap + (j & ~0x7UL));
|
||||||
*(pm + (j / 8)) |= cpumap[j] << (8 * (j & 7));
|
*pm |= (uint64_t)cpumap[j] << (8 * (j & 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hv_versions.hypervisor == 1) {
|
if (hv_versions.hypervisor == 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user