[PATCH 04/15] virBitmapToString: Properly handle empty bitmaps

Peter Krempa pkrempa at redhat.com
Fri Oct 2 07:42:58 UTC 2020


virBitmapNewEmpty() can create a bitmap with 0 lenght. With such a
bitmap virBitmapToString will return NULL rather than an empty string.
Initialize the buffer to avoid that.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/util/virbitmap.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index fcb8e1101a..f1443c3ecf 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -345,6 +345,9 @@ virBitmapToString(virBitmapPtr bitmap)

     sz = bitmap->map_len;

+    /* initialize buffer to return empty string for 0 length bitmap */
+    virBufferAdd(&buf, "", -1);
+
     while (sz--) {
         virBufferAsprintf(&buf, "%0*lx",
                           VIR_BITMAP_BITS_PER_UNIT / 4,
-- 
2.26.2




More information about the libvir-list mailing list