[PATCH 1/6] virBitmapNewCopy: Reimplement bitmap copying to prevent failure

Peter Krempa posted 6 patches 5 years, 4 months ago
[PATCH 1/6] virBitmapNewCopy: Reimplement bitmap copying to prevent failure
Posted by Peter Krempa 5 years, 4 months ago
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>
---
 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 74d1883d94..c62438a3a6 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.26.2

Re: [PATCH 1/6] virBitmapNewCopy: Reimplement bitmap copying to prevent failure
Posted by Ján Tomko 5 years, 4 months ago
On a Friday in 2020, Peter Krempa wrote:
>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>
>---
> src/util/virbitmap.c | 10 ++--------
> 1 file changed, 2 insertions(+), 8 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano