aboutsummaryrefslogtreecommitdiff
path: root/util/hbitmap.c
diff options
context:
space:
mode:
authorJohn Snow <jsnow@redhat.com>2019-07-29 16:35:53 -0400
committerJohn Snow <jsnow@redhat.com>2019-08-16 16:28:02 -0400
commit3bde4b010e7510061dd8055b336c0148610a7dff (patch)
tree9b8e754e0cbef911868146afca366ce085bcd1bf /util/hbitmap.c
parentcf0cd293c6311e0714739a95d022b262e1d9d798 (diff)
downloadqemu-3bde4b010e7510061dd8055b336c0148610a7dff.zip
qemu-3bde4b010e7510061dd8055b336c0148610a7dff.tar.gz
qemu-3bde4b010e7510061dd8055b336c0148610a7dff.tar.bz2
hbitmap: Fix merge when b is empty, and result is not an alias of a
Nobody calls the function like this currently, but we neither prohibit or cope with this behavior. I decided to make the function cope with it. Signed-off-by: John Snow <jsnow@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: 20190709232550.10724-8-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
Diffstat (limited to 'util/hbitmap.c')
-rw-r--r--util/hbitmap.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/util/hbitmap.c b/util/hbitmap.c
index bcc0acd..83927f3 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -785,8 +785,9 @@ bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b)
}
/**
- * Given HBitmaps A and B, let A := A (BITOR) B.
- * Bitmap B will not be modified.
+ * Given HBitmaps A and B, let R := A (BITOR) B.
+ * Bitmaps A and B will not be modified,
+ * except when bitmap R is an alias of A or B.
*
* @return true if the merge was successful,
* false if it was not attempted.
@@ -801,7 +802,13 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HBitmap *result)
}
assert(hbitmap_can_merge(b, result));
- if (hbitmap_count(b) == 0) {
+ if ((!hbitmap_count(a) && result == b) ||
+ (!hbitmap_count(b) && result == a)) {
+ return true;
+ }
+
+ if (!hbitmap_count(a) && !hbitmap_count(b)) {
+ hbitmap_reset_all(result);
return true;
}