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=b1806515c63fe6705eb36b4c6810649d1647a883;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; }