Fix underflow bug in core::str::Searcher::new for haystacks of length < 20

This commit is contained in:
nham 2014-08-18 17:51:51 -04:00
parent 98ec85f19e
commit a4bbb5bab4

View File

@ -562,7 +562,7 @@ enum Searcher {
impl Searcher {
fn new(haystack: &[u8], needle: &[u8]) -> Searcher {
// FIXME: Tune this.
if needle.len() > haystack.len() - 20 {
if needle.len() + 20 > haystack.len() {
Naive(NaiveSearcher::new())
} else {
let searcher = TwoWaySearcher::new(needle);