Skip to content

Commit

Permalink
Fix overflow in ::nth-child()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroyuki Ikezoe committed Apr 26, 2017
1 parent e5762cb commit 1a37e69
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions components/selectors/matching.rs
Expand Up @@ -407,7 +407,7 @@ fn matches_generic_nth_child<E, F>(element: &E,
HAS_SLOW_SELECTOR_LATER_SIBLINGS
});

let mut index = 1;
let mut index: i32 = 1;
let mut next_sibling = if is_from_end {
element.next_sibling_element()
} else {
Expand Down Expand Up @@ -435,11 +435,13 @@ fn matches_generic_nth_child<E, F>(element: &E,
};
}

if a == 0 {
b == index
} else {
(index - b) / a >= 0 &&
(index - b) % a == 0
// Is there a non-negative integer n such that An+B=index?
match index.checked_sub(b) {
None => false,
Some(an) => match an.checked_div(a) {
Some(n) => n >= 0 && a * n == an,
None /* a == 0 */ => an == 0,
},
}
}

Expand Down

0 comments on commit 1a37e69

Please sign in to comment.