Truly independent web browser
AK: Respect ownership when move-assigning a Bitmap
Jelle Raaijmakers37b67de75d99
diff --git a/AK/Bitmap.h b/AK/Bitmap.hindex eb9971ede5b..9fb1f13b25d 100644--- a/AK/Bitmap.h+++ b/AK/Bitmap.h@@ -50,9 +50,11 @@ public:Bitmap& operator=(Bitmap&& other){if (this != &other) {- kfree(m_data);+ if (m_is_owning)+ kfree(m_data);m_data = exchange(other.m_data, nullptr);m_size = exchange(other.m_size, 0);+ m_is_owning = exchange(other.m_is_owning, false);}return *this;}diff --git a/Tests/AK/TestBitmap.cpp b/Tests/AK/TestBitmap.cppindex 0a4fab6855a..0fc79f140e5 100644--- a/Tests/AK/TestBitmap.cpp+++ b/Tests/AK/TestBitmap.cpp@@ -29,6 +29,26 @@ TEST_CASE(construct_empty)EXPECT_EQ(bitmap.size(), 0u);}+TEST_CASE(move_assign_into_non_owning)+{+ Array<u8, 1> storage {};+ Bitmap bitmap { storage.data(), 8 };+ bitmap = MUST(Bitmap::create(8, true));+ EXPECT(bitmap.get(0));+ EXPECT_EQ(storage[0], 0u);+}++TEST_CASE(move_assign_from_non_owning)+{+ Array<u8, 1> storage { 0x01 };+ {+ Bitmap bitmap;+ bitmap = Bitmap { storage.data(), 8 };+ EXPECT(bitmap.get(0));+ }+ EXPECT_EQ(storage[0], 0x01u);+}+TEST_CASE(find_first_set){auto bitmap = MUST(Bitmap::create(128, false));