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

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

 



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@xxxxxxxxxx>
---
 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




[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