]> xenbits.xensource.com Git - libvirt.git/commitdiff
bitmap: fix typo to use UL type of integer constant in virBitmapIsAllSet
authorGuannan Ren <gren@redhat.com>
Wed, 28 Nov 2012 06:15:38 +0000 (14:15 +0800)
committerGuannan Ren <gren@redhat.com>
Wed, 28 Nov 2012 10:30:28 +0000 (18:30 +0800)
This bug leads to getting incorrect vcpupin information via
qemudDomainGetVcpuPinInfo() API when the number of maximum
cpu on a host falls into a range such as 31 < ncpus < 64.

gcc warning:
left shift count >= width of type

The following bug is such the case
https://bugzilla.redhat.com/show_bug.cgi?id=876415

src/util/bitmap.c
tests/virbitmaptest.c

index 5ec54400b17b52183c79e208c83f519ccb99f955..c29f5f36c7f38fea3a5ff32cd86132b9d7549c01 100644 (file)
@@ -574,8 +574,8 @@ bool virBitmapIsAllSet(virBitmapPtr bitmap)
             return false;
 
     if (unusedBits > 0) {
-        if ((bitmap->map[sz] & ((1U << (VIR_BITMAP_BITS_PER_UNIT - unusedBits)) - 1))
-            != ((1U << (VIR_BITMAP_BITS_PER_UNIT - unusedBits)) - 1))
+        if ((bitmap->map[sz] & ((1UL << (VIR_BITMAP_BITS_PER_UNIT - unusedBits)) - 1))
+            != ((1UL << (VIR_BITMAP_BITS_PER_UNIT - unusedBits)) - 1))
             return false;
     }
 
index f1eb9d5511dcbfb8da9f6bc8618f0745dd06b39d..af94dab5f5f937be0202fef6fb60c4f4db1e82fe 100644 (file)
@@ -347,6 +347,41 @@ error:
     return ret;
 }
 
+static int test7(const void *v ATTRIBUTE_UNUSED)
+{
+    virBitmapPtr bitmap;
+    size_t i;
+    size_t maxBit[] = {
+        1, 8, 31, 32, 63, 64, 95, 96, 127, 128, 159, 160
+    };
+    size_t nmaxBit = 12;
+
+    for (i = 0; i < nmaxBit; i++) {
+        bitmap = virBitmapNew(maxBit[i]);
+        if (!bitmap)
+            goto error;
+
+        if (virBitmapIsAllSet(bitmap))
+            goto error;
+
+        ignore_value(virBitmapSetBit(bitmap, 1));
+        if (virBitmapIsAllSet(bitmap))
+            goto error;
+
+        virBitmapSetAll(bitmap);
+        if (!virBitmapIsAllSet(bitmap))
+            goto error;
+
+        virBitmapFree(bitmap);
+    }
+
+    return 0;
+
+error:
+    virBitmapFree(bitmap);
+    return -1;
+}
+
 static int
 mymain(void)
 {
@@ -364,6 +399,8 @@ mymain(void)
         ret = -1;
     if (virtTestRun("test6", 1, test6, NULL) < 0)
         ret = -1;
+    if (virtTestRun("test7", 1, test7, NULL) < 0)
+        ret = -1;
 
 
     return ret;