mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb: Don't crash when converting small CSS::Ratio to CSSPixelFraction
Previously, a crash would occur in the if `CSSPixelFraction` was given a denominator value less than the resolution of `CSSPixels` (1/64). We now divide both parts of the ratio by the denominator in this case.
This commit is contained in:
parent
785180dd45
commit
2c5d626b21
Notes:
github-actions[bot]
2024-08-22 11:50:33 +00:00
Author: https://github.com/tcl3
Commit: 2c5d626b21
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1160
4 changed files with 27 additions and 1 deletions
|
@ -320,6 +320,20 @@ public:
|
|||
VERIFY(denominator != 0);
|
||||
}
|
||||
|
||||
template<FloatingPoint F>
|
||||
constexpr CSSPixelFraction(F numerator, F denominator = 1)
|
||||
{
|
||||
if (CSSPixels::nearest_value_for(denominator) == 0) {
|
||||
numerator = numerator / denominator;
|
||||
denominator = 1;
|
||||
}
|
||||
|
||||
m_numerator = CSSPixels(numerator);
|
||||
m_denominator = CSSPixels(denominator);
|
||||
|
||||
VERIFY(denominator != 0);
|
||||
}
|
||||
|
||||
constexpr operator CSSPixels() const
|
||||
{
|
||||
i64 wide_value = m_numerator.raw_value();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue