Comment 15 for bug 655463

Revision history for this message
In , Eric Blake (eblake) wrote :

Your test for (memory > shift) will never be reached. Other than the assignment added by your proposed patch, memory is only ever assigned to be 0 or needle_len - period. And for a periodic needle, shift is either needle_len or < period, by virtue of how the shift table is constructed. Therefore, if memory is non-zero but shift >= period, then shift is necessarily > memory at that point.

Which means your code can be reduced to this simpler patch:

diff --git i/string/str-two-way.h w/string/str-two-way.h
index 502af47..76044b3 100644
--- i/string/str-two-way.h
+++ w/string/str-two-way.h
@@ -350,8 +350,8 @@ two_way_long_needle (const unsigned char *haystack,
        a byte out of place, there can be no match until
        after the mismatch. */
     shift = needle_len - period;
- memory = 0;
   }
+ memory = 0;
        j += shift;
        continue;
      }