diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 4ca59f9d62..8c62937706 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -817,7 +817,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; @@ -836,8 +840,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--) {