mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibWeb: Clamp interpolated values to the range of their numeric type
This fixes a UBSAN warning that we previously hit when interpolating color values.
This commit is contained in:
parent
58ffc56c38
commit
09f4d90594
Notes:
github-actions[bot]
2025-05-19 10:32:56 +00:00
Author: https://github.com/tcl3
Commit: 09f4d90594
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4811
Reviewed-by: https://github.com/AtkinsSJ ✅
4 changed files with 584 additions and 592 deletions
|
@ -38,9 +38,13 @@ static T interpolate_raw(T from, T to, float delta)
|
|||
{
|
||||
if constexpr (AK::Detail::IsSame<T, double>) {
|
||||
return from + (to - from) * static_cast<double>(delta);
|
||||
} else {
|
||||
return static_cast<AK::Detail::RemoveCVReference<T>>(from + (to - from) * delta);
|
||||
} else if constexpr (AK::Detail::IsIntegral<T>) {
|
||||
auto from_float = static_cast<float>(from);
|
||||
auto to_float = static_cast<float>(to);
|
||||
auto unclamped_result = from_float + (to_float - from_float) * delta;
|
||||
return static_cast<AK::Detail::RemoveCVReference<T>>(clamp(unclamped_result, NumericLimits<T>::min(), NumericLimits<T>::max()));
|
||||
}
|
||||
return static_cast<AK::Detail::RemoveCVReference<T>>(from + (to - from) * delta);
|
||||
}
|
||||
|
||||
static NonnullRefPtr<CSSStyleValue const> with_keyword_values_resolved(DOM::Element& element, PropertyID property_id, CSSStyleValue const& value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue