From 6b18cafb1dea4703f2ef9ec7f58b801a713b787f Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 2 Oct 2020 10:22:18 +0200 Subject: [PATCH] virBitmapNewCopy: Reimplement bitmap copying to prevent failure MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit virBitmapCopy has a failure condition, which is impossible to meet when creating a new copy. Copy the contents directly to make it obvious that virBitmapNewCopy can't fail. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/util/virbitmap.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 5f6136367a..ee540e15a9 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -655,20 +655,14 @@ virBitmapParseUnlimited(const char *str) * virBitmapNewCopy: * @src: the source bitmap. * - * Makes a copy of bitmap @src. - * - * returns the copied bitmap on success, or NULL otherwise. Caller - * should call virBitmapFree to free the returned bitmap. + * Returns a copy of bitmap @src. */ virBitmapPtr virBitmapNewCopy(virBitmapPtr src) { virBitmapPtr dst = virBitmapNew(src->nbits); - if (virBitmapCopy(dst, src) != 0) { - virBitmapFree(dst); - return NULL; - } + memcpy(dst->map, src->map, src->map_len * sizeof(src->map[0])); return dst; } -- 2.47.2