From: Ben Pfaff Date: Sun, 5 Sep 2004 08:29:42 +0000 (+0000) Subject: Handle bit_cnt of 0 properly. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=a5f4589c0167c2124c2e9b9b895bec1257d11f92;p=pintos-anon Handle bit_cnt of 0 properly. --- 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. */