summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/virbitmap.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c
index c94764792f..3610feb4d0 100644
--- a/src/util/virbitmap.c
+++ b/src/util/virbitmap.c
@@ -724,7 +724,11 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
ssize_t i;
int unusedBits;
ssize_t sz;
- unsigned long bits = 0;
+ unsigned long bits;
+
+ /* If bitmap is empty then there is no set bit */
+ if (bitmap->map_len == 0)
+ return -1;
unusedBits = bitmap->map_len * VIR_BITMAP_BITS_PER_UNIT - bitmap->max_bit;
@@ -743,8 +747,8 @@ virBitmapLastSetBit(virBitmapPtr bitmap)
goto found;
}
- if (bits == 0)
- return -1;
+ /* Only reached if no set bit was found */
+ return -1;
found:
for (i = VIR_BITMAP_BITS_PER_UNIT - 1; i >= 0; i--) {