[PATCH 08/15] util: virbitmap: Don't forbid 0 size bitmap

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

 



We now have APIs which automatically expand the bitmap and also API
which allocates a 0 size bitmap. Remove the condition from virBitmapNew.

Effectively reverts ce49cfb48ad

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virbitmap.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index f1443c3ecf..5df7ea7838 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -55,8 +55,8 @@ struct _virBitmap {
  *
  * Allocate a bitmap capable of containing @size bits.
  *
- * Returns a pointer to the allocated bitmap or NULL if either memory cannot be
- * allocated or size is 0. Does not report libvirt errors.
+ * Returns a pointer to the allocated bitmap or NULL if memory cannot be
+ * allocated. Does not report libvirt errors.
  */
 virBitmapPtr
 virBitmapNewQuiet(size_t size)
@@ -64,12 +64,16 @@ virBitmapNewQuiet(size_t size)
     virBitmapPtr bitmap;
     size_t sz;

-    if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size || size == 0)
+    if (SIZE_MAX - VIR_BITMAP_BITS_PER_UNIT < size)
         return NULL;

     sz = VIR_DIV_UP(size, VIR_BITMAP_BITS_PER_UNIT);

     bitmap = g_new0(virBitmap, 1);
+
+    if (size == 0)
+        return bitmap;
+
     bitmap->map = g_new0(unsigned long, sz);
     bitmap->nbits = size;
     bitmap->map_len = sz;
-- 
2.26.2




[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