#13 Bug in pattern-matching in Script class

open
nobody
None
5
2002-12-14
2002-12-14
Anonymous
No

You have the bug here:

private void match(byte[] s, int length) throws
IOException {
for(int i = 0; !done && i < length; i++) {
if(s[i] == match[matchPos]) {
// the whole thing matched so, return the match
answer
// and reset to use the next match
if(++matchPos >= match.length)
write(found());
} else
reset();
}
}

It doesn't work with s = abababc and match = ababc,
because you move your position in "match" to the
begining without moving in "s". If the current
character doesn't match you simply move whole pattern
forgetting that the pattern may match at position
beetwen current position and the begining of last
matched prefix.

Discussion