]> xenbits.xensource.com Git - libvirt.git/commitdiff
virBitmapIsBitSet: Allow NULL bitmap
authorPeter Krempa <pkrempa@redhat.com>
Wed, 9 Nov 2022 15:54:56 +0000 (16:54 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Feb 2023 08:14:00 +0000 (09:14 +0100)
The virBitmapIsBitSet API is a permissive one which returns false when
the bit is not set or is out of range. We can do the same if the bitmap
is NULL to aid certain situations when this can happen, but we don't
want to add extra checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
src/util/virbitmap.c
src/util/virbitmap.h

index 5b9204cbd7a536fb810d4f83e24d2038e9671b4e..bdcbd0aece5f214e491625d947861be561b108d9 100644 (file)
@@ -216,7 +216,7 @@ virBitmapIsSet(virBitmap *bitmap, size_t b)
 
 /**
  * virBitmapIsBitSet:
- * @bitmap: Pointer to bitmap
+ * @bitmap: Pointer to bitmap (May be NULL)
  * @b: bit position to get
  *
  * Get setting of bit position @b in @bitmap.
@@ -228,7 +228,7 @@ bool
 virBitmapIsBitSet(virBitmap *bitmap,
                   size_t b)
 {
-    if (bitmap->nbits <= b)
+    if (!bitmap || bitmap->nbits <= b)
         return false;
 
     return virBitmapIsSet(bitmap, b);
index e2314904b0c37f0df47b74ca2b61abc2ff1e84d3..dbd88c9bb529ec77137ac88351d9f1c175f6e3de 100644 (file)
@@ -61,7 +61,7 @@ void virBitmapClearBitExpand(virBitmap *bitmap, size_t b)
  * Get bit @b in @bitmap. Returns false if b is out of range.
  */
 bool virBitmapIsBitSet(virBitmap *bitmap, size_t b)
-    ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
+    G_GNUC_WARN_UNUSED_RESULT;
 /*
  * Get setting of bit position @b in @bitmap and store in @result
  */