From: Peter Krempa Date: Fri, 2 Oct 2020 08:22:18 +0000 (+0200) Subject: virBitmapNewCopy: Reimplement bitmap copying to prevent failure X-Git-Tag: v6.9.0-rc1~356 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6b18cafb1dea4703f2ef9ec7f58b801a713b787f;p=thirdparty%2Flibvirt.git virBitmapNewCopy: Reimplement bitmap copying to prevent failure 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 --- 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; }