1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 20:07:35 +00:00

AK: Fix one-off error in BitmapView::find_first and find_one_anywhere

The mentioned functions used m_size / 8 instead of size_in_bytes()
(division with ceiling rounding mode), which resulted in an off-by-one
error such that the functions didn't search in the last not-fully-8-bits
byte.

Using size_in_bytes() instead of m_size / 8 fixes this.
This commit is contained in:
Martin Janiczek 2023-10-11 13:52:38 +02:00 committed by Tim Schumacher
parent 2e615b5316
commit efa5fb5c3a
2 changed files with 21 additions and 3 deletions

View file

@ -276,3 +276,21 @@ TEST_CASE(byte_aligned_access)
EXPECT_EQ(bitmap.count_in_range(4, 4, true), 1u);
}
}
TEST_CASE(find_one_anywhere_edge_case)
{
{
auto bitmap = MUST(Bitmap::create(1, false));
bitmap.set(0, false);
EXPECT_EQ(bitmap.find_one_anywhere_unset(0).value(), 0UL);
}
}
TEST_CASE(find_first_edge_case)
{
{
auto bitmap = MUST(Bitmap::create(1, false));
bitmap.set(0, false);
EXPECT_EQ(bitmap.find_first_unset().value(), 0UL);
}
}