]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virBitmapToString: Properly handle empty bitmaps
authorPeter Krempa <pkrempa@redhat.com>
Thu, 1 Oct 2020 12:13:37 +0000 (14:13 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 5 Oct 2020 10:26:22 +0000 (12:26 +0200)
virBitmapNewEmpty() can create a bitmap with 0 length. 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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virbitmap.c

index ed28427736854ab2b1267ce3b3f25d6b246d3534..a99902377744d049412301a1ff90c405ba80ee33 100644 (file)
@@ -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,