From: Peter Krempa Date: Thu, 1 Oct 2020 12:13:37 +0000 (+0200) Subject: virBitmapToString: Properly handle empty bitmaps X-Git-Tag: v6.9.0-rc1~386 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2d13d607f23f6a219d50da2a9dfea5e934f4c95;p=thirdparty%2Flibvirt.git 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 Reviewed-by: Ján Tomko --- 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,