virBitmapToString: Properly handle empty bitmaps

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>
This commit is contained in:
Peter Krempa 2020-10-01 14:13:37 +02:00
parent 2eada815b5
commit e2d13d607f

View 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,