Prevent bitmap_scan() from assert-failing if CNT is greater than the
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 5 Nov 2004 23:12:11 +0000 (23:12 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 5 Nov 2004 23:12:11 +0000 (23:12 +0000)
bitmap's size.

src/lib/kernel/bitmap.c

index cacc263a200b5fea1dc440afdc3249788681567f..95d689034617917f9cd23ef7b5423978fa774cec 100644 (file)
@@ -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;
 }