From e2d13d607f23f6a219d50da2a9dfea5e934f4c95 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 1 Oct 2020 14:13:37 +0200 Subject: [PATCH] virBitmapToString: Properly handle empty bitmaps MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ján Tomko --- src/util/virbitmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index ed28427736..a999023777 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.47.2