desktop/reserved: fix a possible reserved crash (#13207)

This commit is contained in:
Vaxry 2026-02-10 14:59:21 +00:00 committed by GitHub
parent ff061d177e
commit 339661229d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View file

@ -16,7 +16,8 @@ CReservedArea::CReservedArea(double top, double right, double bottom, double lef
}
CReservedArea::CReservedArea(const CBox& parent, const CBox& child) {
ASSERT(!parent.empty() && !child.empty());
if (parent.empty() || child.empty())
return; // empty reserved area
ASSERT(parent.containsPoint(child.pos() + Vector2D{0.0001, 0.0001}));
ASSERT(parent.containsPoint(child.pos() + child.size() - Vector2D{0.0001, 0.0001}));

View file

@ -35,4 +35,18 @@ TEST(Desktop, reservedArea) {
EXPECT_EQ(b.top(), 30 - 10);
EXPECT_EQ(b.right(), 1010 - 920);
EXPECT_EQ(b.bottom(), 1010 - 930);
Desktop::CReservedArea c{CBox{}, CBox{20, 30, 900, 900}};
EXPECT_EQ(c.left(), 0);
EXPECT_EQ(c.top(), 0);
EXPECT_EQ(c.right(), 0);
EXPECT_EQ(c.bottom(), 0);
Desktop::CReservedArea d{CBox{20, 30, 900, 900}, CBox{}};
EXPECT_EQ(d.left(), 0);
EXPECT_EQ(d.top(), 0);
EXPECT_EQ(d.right(), 0);
EXPECT_EQ(d.bottom(), 0);
}