[libvirt] [PATCH v3] bitmap: fix typo to use UL type of integer constant in virBitmapIsAllSet

Hu Tao hutao at cn.fujitsu.com
Wed Nov 28 10:10:01 UTC 2012


On Wed, Nov 28, 2012 at 02:24:31PM +0800, Guannan Ren wrote:
> 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     |  4 ++--
>  tests/virbitmaptest.c | 37 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+), 2 deletions(-)
> 
> diff --git a/src/util/bitmap.c b/src/util/bitmap.c
> index 5ec5440..c29f5f3 100644
> --- a/src/util/bitmap.c
> +++ b/src/util/bitmap.c
> @@ -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;
>      }
>  
> diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c
> index f1eb9d5..af94dab 100644
> --- a/tests/virbitmaptest.c
> +++ b/tests/virbitmaptest.c
> @@ -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;
> -- 
> 1.7.11.2

Looks OK to me.


-- 
Hu Tao




More information about the libvir-list mailing list