mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:17:35 +00:00
LibWeb: Implement subtraction using saturated_addition in CSSPixels
Fixes overflow bug found by UBSAN.
This commit is contained in:
parent
26c20e3da1
commit
c431167736
2 changed files with 12 additions and 1 deletions
|
@ -76,4 +76,15 @@ TEST_CASE(comparison2)
|
||||||
EXPECT_EQ(CSSPixels(123) == CSSPixels(123), true);
|
EXPECT_EQ(CSSPixels(123) == CSSPixels(123), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE(saturated_addition)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(CSSPixels(INFINITY), CSSPixels(INFINITY) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE(saturated_subtraction)
|
||||||
|
{
|
||||||
|
auto value = CSSPixels(INFINITY);
|
||||||
|
EXPECT_EQ(value - -1, CSSPixels(INFINITY));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ CSSPixels CSSPixels::operator+(CSSPixels const& other) const
|
||||||
CSSPixels CSSPixels::operator-(CSSPixels const& other) const
|
CSSPixels CSSPixels::operator-(CSSPixels const& other) const
|
||||||
{
|
{
|
||||||
CSSPixels result;
|
CSSPixels result;
|
||||||
result.set_raw_value(raw_value() - other.raw_value());
|
result.set_raw_value(saturated_addition(raw_value(), -other.raw_value()));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue