servo: Merge #19652 - Fix division by zero in gradient stop calculation (from pyfisch:issue18435); r=emilio

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. -->

Source-Repo: https://github.com/servo/servo
Source-Revision: 1ce6d8ea2d2bbb4d6f095ac62514eca942599e83

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : e30331dc8bdbe4af4687be81956e31850d4e5613
This commit is contained in:
Pyfisch 2018-01-01 09:38:07 -06:00
Родитель 12c64e4849
Коммит 643bbbf5a0
1 изменённых файлов: 4 добавлений и 0 удалений

Просмотреть файл

@ -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,