]> xenbits.xensource.com Git - libvirt.git/commitdiff
hypervisor: Revisit Coverity issues regarding cpumap
authorJohn Ferlan <jferlan@redhat.com>
Wed, 30 Jan 2013 18:09:13 +0000 (13:09 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 11 Feb 2013 14:50:11 +0000 (09:50 -0500)
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.

src/xen/xen_hypervisor.c

index 9c42b60224e2acf93360da42c02d05a123c5005b..767fc0cf65488a97e776ac973e12dafe71d207bd 100644 (file)
@@ -1773,17 +1773,17 @@ virXen_setvcpumap(int handle,
             ret = -1;
     } else {
         cpumap_t xen_cpumap; /* limited to 64 CPUs in old hypervisors */
-        uint64_t *pm = &xen_cpumap;
+        uint64_t *pm;
         int j;
 
         if ((maplen > (int)sizeof(cpumap_t)) || (sizeof(cpumap_t) & 7))
             return -1;
 
-        memset(pm, 0, sizeof(cpumap_t));
+        memset(&xen_cpumap, 0, sizeof(cpumap_t));
         for (j = 0; j < maplen; j++) {
-            /* coverity[ptr_arith] */
-            /* coverity[sign_extension] */
-            *(pm + (j / 8)) |= cpumap[j] << (8 * (j & 7));
+            if ((j & 7) == 0)
+                pm = (uint64_t *)((uint64_t)&xen_cpumap + (j & ~0x7UL));
+            *pm |= (uint64_t)cpumap[j] << (8 * (j & 7));
         }
 
         if (hv_versions.hypervisor == 1) {