mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #19652 - pyfisch:issue18435, r=emilio
Fix division by zero in gradient stop calculation Check if total_length is zero and return 0.0 instead of NaN in this case. Closes #18435 <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #18435 (github issue number if applicable). <!-- Either: --> - [x] There are tests for these changes OR - [x] These changes do not require tests because simple bugfix/no idea for good test <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19652) <!-- Reviewable:end -->
This commit is contained in:
commit
1ce6d8ea2d
4 changed files with 42 additions and 0 deletions
|
@ -798,6 +798,7 @@ fn convert_gradient_stops(gradient_items: &[GradientItem],
|
|||
position_to_offset(position, total_length)
|
||||
}
|
||||
};
|
||||
assert!(offset.is_finite());
|
||||
stops.push(GradientStop {
|
||||
offset: offset,
|
||||
color: stop.color.to_gfx_color()
|
||||
|
@ -3270,6 +3271,9 @@ struct StopRun {
|
|||
}
|
||||
|
||||
fn position_to_offset(position: LengthOrPercentage, total_length: Au) -> f32 {
|
||||
if total_length == Au(0) {
|
||||
return 0.0
|
||||
}
|
||||
match position {
|
||||
LengthOrPercentage::Length(l) => l.to_i32_au() as f32 / total_length.0 as f32,
|
||||
LengthOrPercentage::Percentage(percentage) => percentage.0 as f32,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue