From b1806515c63fe6705eb36b4c6810649d1647a883 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 5 Nov 2004 23:12:11 +0000 Subject: [PATCH] Prevent bitmap_scan() from assert-failing if CNT is greater than the bitmap's size. --- src/lib/kernel/bitmap.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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; } -- 2.30.2