bitmap: fix typo to use UL type of integer constant in virBitmapIsAllSet

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
This commit is contained in:
Guannan Ren 2012-11-28 14:15:38 +08:00
parent 8927c0eab6
commit 237629d204
2 changed files with 39 additions and 2 deletions

View 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;
}

View 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;