Prevent bitmap_scan() from assert-failing if CNT is greater than the
[pintos-anon] / 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;
 }