[PATCH 1/5] virbitmap: Allow NULL bitmap in functions returning index of a set/clear bit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virBitmapNextSetBit/virBitmapLastSetBit/virBitmapNextClearBit can be
used for iteration of a bitmap. Allow NULL bitmap so that iteration of a
bitmap can be simplified in certain cases.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virbitmap.c | 9 +++++++++
 src/util/virbitmap.h | 9 +++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index 5b9204cbd7..690ac592ba 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -824,6 +824,9 @@ virBitmapNextSetBit(virBitmap *bitmap,
     size_t nb;
     unsigned long bits;

+    if (!bitmap)
+        return -1;
+
     if (pos < 0)
         pos = -1;

@@ -863,6 +866,9 @@ virBitmapLastSetBit(virBitmap *bitmap)
     ssize_t sz;
     unsigned long bits;

+    if (!bitmap)
+        return -1;
+
     /* If bitmap is empty then there is no set bit */
     if (bitmap->map_len == 0)
         return -1;
@@ -916,6 +922,9 @@ virBitmapNextClearBit(virBitmap *bitmap,
     size_t nb;
     unsigned long bits;

+    if (!bitmap)
+        return -1;
+
     if (pos < 0)
         pos = -1;

diff --git a/src/util/virbitmap.h b/src/util/virbitmap.h
index e2314904b0..9f954f5ee7 100644
--- a/src/util/virbitmap.h
+++ b/src/util/virbitmap.h
@@ -111,14 +111,11 @@ bool virBitmapIsAllSet(virBitmap *bitmap)
 bool virBitmapIsAllClear(virBitmap *bitmap)
     ATTRIBUTE_NONNULL(1);

-ssize_t virBitmapNextSetBit(virBitmap *bitmap, ssize_t pos)
-    ATTRIBUTE_NONNULL(1);
+ssize_t virBitmapNextSetBit(virBitmap *bitmap, ssize_t pos);

-ssize_t virBitmapLastSetBit(virBitmap *bitmap)
-    ATTRIBUTE_NONNULL(1);
+ssize_t virBitmapLastSetBit(virBitmap *bitmap);

-ssize_t virBitmapNextClearBit(virBitmap *bitmap, ssize_t pos)
-    ATTRIBUTE_NONNULL(1);
+ssize_t virBitmapNextClearBit(virBitmap *bitmap, ssize_t pos);

 size_t virBitmapCountBits(virBitmap *bitmap)
     ATTRIBUTE_NONNULL(1);
-- 
2.39.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux