mirror of
https://github.com/servo/servo.git
synced 2025-07-25 16:20:36 +01:00
Fix overflow in ::nth-child()
This commit is contained in:
parent
e5762cb695
commit
1a37e69ce9
1 changed files with 8 additions and 6 deletions
|
@ -407,7 +407,7 @@ fn matches_generic_nth_child<E, F>(element: &E,
|
||||||
HAS_SLOW_SELECTOR_LATER_SIBLINGS
|
HAS_SLOW_SELECTOR_LATER_SIBLINGS
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut index = 1;
|
let mut index: i32 = 1;
|
||||||
let mut next_sibling = if is_from_end {
|
let mut next_sibling = if is_from_end {
|
||||||
element.next_sibling_element()
|
element.next_sibling_element()
|
||||||
} else {
|
} else {
|
||||||
|
@ -435,11 +435,13 @@ fn matches_generic_nth_child<E, F>(element: &E,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if a == 0 {
|
// Is there a non-negative integer n such that An+B=index?
|
||||||
b == index
|
match index.checked_sub(b) {
|
||||||
} else {
|
None => false,
|
||||||
(index - b) / a >= 0 &&
|
Some(an) => match an.checked_div(a) {
|
||||||
(index - b) % a == 0
|
Some(n) => n >= 0 && a * n == an,
|
||||||
|
None /* a == 0 */ => an == 0,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue