From: Ben Pfaff Date: Fri, 5 Nov 2004 23:12:11 +0000 (+0000) Subject: Prevent bitmap_scan() from assert-failing if CNT is greater than the X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc637378f55d2e5d39ef4ebd58e3a3b1a13a4fa9;p=pintos-anon Prevent bitmap_scan() from assert-failing if CNT is greater than the bitmap's size. --- diff --git a/src/lib/kernel/bitmap.c b/src/lib/kernel/bitmap.c index cacc263..95d6890 100644 --- a/src/lib/kernel/bitmap.c +++ b/src/lib/kernel/bitmap.c @@ -216,9 +216,10 @@ bitmap_scan (const struct bitmap *b, size_t start, size_t cnt, bool value) ASSERT (b != NULL); ASSERT (start <= b->bit_cnt); - for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++) - if (!contains (b, idx, idx + cnt, !value)) - return idx; + if (cnt <= b->bit_cnt) + for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++) + if (!contains (b, idx, idx + cnt, !value)) + return idx; return BITMAP_ERROR; }