Sunday, August 24, 2014

Yet Another Integer Underflow Bug

Nick Hamann (via David Smith):

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

Comments RSS · Twitter

Leave a Comment