diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 32767631334495eec40812f7614c486056ca861d..2029a735f7d67c9bd6ec2127f9ff62da80984812 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -952,7 +952,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; @@ -971,8 +975,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--) {