]> xenbits.xensource.com Git - libvirt.git/commitdiff
libxl: avoid compiler warning
authorEric Blake <eblake@redhat.com>
Tue, 5 Apr 2011 16:07:57 +0000 (10:07 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 5 Apr 2011 17:09:12 +0000 (11:09 -0600)
cc1: warnings being treated as errors
libxl/libxl_driver.c: In function 'libxlDomainSetVcpusFlags':
libxl/libxl_driver.c:1570:14: error: cast from function call of type 'double' to non-matching type 'unsigned int' [-Wbad-function-cast]
libxl/libxl_driver.c:1578:15: error: cast from function call of type 'double' to non-matching type 'unsigned int' [-Wbad-function-cast]

This was the only use of floor() and ceil(), and floating-point
is overkill for power-of-two manipulations.

* src/libxl/libxl_driver.c (libxlDomainSetVcpusFlags): Avoid -lm
for trivial computations.

src/libxl/libxl_driver.c

index 75f99c1f0a6e00a9be73890f20ab901c36b4aa89..8cc4469007f72c7e53e7c2d445f16fed2b71a0f4 100644 (file)
@@ -1567,15 +1567,14 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
     if (!(def = virDomainObjGetPersistentDef(driver->caps, vm)))
         goto cleanup;
 
-    maplen = (unsigned int) ceil((double) nvcpus / 8);
+    maplen = VIR_CPU_MAPLEN(nvcpus);
     if (VIR_ALLOC_N(bitmask, maplen) < 0) {
         virReportOOMError();
         goto cleanup;
     }
 
-    memset(bitmask, 0, maplen);
     for (i = 0; i < nvcpus; ++i) {
-        pos = (unsigned int) floor((double) i / 8);
+        pos = i / 8;
         bitmask[pos] |= 1 << (i % 8);
     }