From a5f4589c0167c2124c2e9b9b895bec1257d11f92 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 5 Sep 2004 08:29:42 +0000 Subject: [PATCH] Handle bit_cnt of 0 properly. --- src/lib/bitmap.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c index c5ca38a..8357d2e 100644 --- a/src/lib/bitmap.c +++ b/src/lib/bitmap.c @@ -101,9 +101,12 @@ bitmap_set_all (struct bitmap *b, bool value) ASSERT (b != NULL); - for (i = 0; i < elem_cnt (b); i++) - b->bits[i] = value ? (elem_type) -1 : 0; - b->bits[elem_cnt (b) - 1] &= last_mask (b); + if (b->bit_cnt > 0) + { + for (i = 0; i < elem_cnt (b); i++) + b->bits[i] = value ? (elem_type) -1 : 0; + b->bits[elem_cnt (b) - 1] &= last_mask (b); + } } /* Sets the bit numbered IDX in B to true. */ @@ -274,8 +277,11 @@ bitmap_file_size (const struct bitmap *b) void bitmap_read (struct bitmap *b, struct file *file) { - file_read_at (file, b->bits, byte_cnt (b), 0); - b->bits[elem_cnt (b) - 1] &= last_mask (b); + if (b->bit_cnt > 0) + { + file_read_at (file, b->bits, byte_cnt (b), 0); + b->bits[elem_cnt (b) - 1] &= last_mask (b); + } } /* Writes FILE to B, ignoring errors. */ -- 2.30.2