From edac559ea668821b9ad4abaf35baa8f2c9d08384 Mon Sep 17 00:00:00 2001 From: Ethan Pailes Date: Fri, 9 Feb 2018 11:16:55 -0500 Subject: [PATCH] Closes #446 This patch fixes an issue where skip resolution would go strait to the default value (the md2_shift) on a match failure after the shift_loop. Now we do the right thing, and first check in the skip table. The problem with going strait to the md2_shift is that you can accidentally shift to far when `window_end` actually is in the pattern (as is the case for the failing match). In the issue thread I promised better modularity, but it turns out that shift resolution was a bit too decomposed in the other places I had mentioned. Sorry :(. --- src/literals.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/literals.rs b/src/literals.rs index 852d4e761d..72c210b858 100644 --- a/src/literals.rs +++ b/src/literals.rs @@ -627,7 +627,9 @@ impl BoyerMooreSearch { if self.check_match(haystack, window_end) { return Some(window_end - (self.pattern.len() - 1)); } else { - window_end += self.md2_shift; + let skip = self.skip_table[haystack[window_end] as usize]; + window_end += + if skip == 0 { self.md2_shift } else { skip }; continue; } } @@ -946,7 +948,6 @@ mod tests { } #[test] - #[should_panic] fn bm_backstop_boundary() { let haystack = b"\ // aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa