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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-10-02 10:22:18 +02:00
parent cb6fdb0125
commit 6b18cafb1d

View File

@ -655,20 +655,14 @@ virBitmapParseUnlimited(const char *str)
* virBitmapNewCopy: * virBitmapNewCopy:
* @src: the source bitmap. * @src: the source bitmap.
* *
* Makes a copy of bitmap @src. * Returns a copy of bitmap @src.
*
* returns the copied bitmap on success, or NULL otherwise. Caller
* should call virBitmapFree to free the returned bitmap.
*/ */
virBitmapPtr virBitmapPtr
virBitmapNewCopy(virBitmapPtr src) virBitmapNewCopy(virBitmapPtr src)
{ {
virBitmapPtr dst = virBitmapNew(src->nbits); virBitmapPtr dst = virBitmapNew(src->nbits);
if (virBitmapCopy(dst, src) != 0) { memcpy(dst->map, src->map, src->map_len * sizeof(src->map[0]));
virBitmapFree(dst);
return NULL;
}
return dst; return dst;
} }