haystack.len()is less than 20,
haystack.len() - 20will be a very large number; we have an underflow error on our hands. This bug was causing the code to erroneously use the
TwoWaySearcherin general for haystacks of length less than 20, but in particular for the case of
"bananas".contains("nana"). The fix is to add
20to the needle instead of subtracting it from the haystack […]
Stay up-to-date by subscribing to the Comments RSS Feed for this post.