aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/display_list_builder.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-01-01 09:38:07 -0600
committerGitHub <noreply@github.com>2018-01-01 09:38:07 -0600
commit1ce6d8ea2d2bbb4d6f095ac62514eca942599e83 (patch)
tree22e24efd78f35cdeb14165454f4bc70f07198cc8 /components/layout/display_list_builder.rs
parent657d8a2ede97e7f7fedee5ada97c833abe5a8d9e (diff)
parent94f3e3353dfe44d980374fdad3bc9a7c4d97096d (diff)
downloadservo-1ce6d8ea2d2bbb4d6f095ac62514eca942599e83.tar.gz
servo-1ce6d8ea2d2bbb4d6f095ac62514eca942599e83.zip
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 -->
Diffstat (limited to 'components/layout/display_list_builder.rs')
-rw-r--r--components/layout/display_list_builder.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs
index 034e5a2d539..97b1ba4c7dc 100644
--- a/components/layout/display_list_builder.rs
+++ b/components/layout/display_list_builder.rs
@@ -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,