Fix bug reported by Roger Peppe, namely that regexec(regcomp("^good"), "hello\ngoodbye", nil, 0) == 0 The code to skip forward line by line when matching a pattern beginning with ^ was off by one in regexec.c. I changed rregexec.c to use the new(er than libregexp) runestrchr function so that it looks more like regexec. Reference: /n/sources/patch/applied/regexec Date: Fri May 18 18:50:59 CES 2007 Signed-off-by: rsc@swtch.com --- /sys/src/libregexp/regexec.c Fri May 18 18:49:19 2007 +++ /sys/src/libregexp/regexec.c Fri May 18 18:49:19 2007 @@ -59,7 +59,7 @@ p = utfrune(s, '\n'); if(p == 0 || s == j->eol) return match; - s = p; + s = p+1; break; } } --- /sys/src/libregexp/rregexec.c Fri May 18 18:49:21 2007 +++ /sys/src/libregexp/rregexec.c Fri May 18 18:49:21 2007 @@ -26,6 +26,7 @@ Relist* tle; /* ends of this and next list */ Relist* nle; int match; + Rune *p; match = 0; checkstart = j->startchar; @@ -40,25 +41,22 @@ /* Execute machine once for each character, including terminal NUL */ s = j->rstarts; do{ - /* fast check for first char */ if(checkstart) { switch(j->starttype) { case RUNE: - while(*s != j->startchar) { - if(*s == 0 || s == j->reol) - return match; - s++; - } + p = runestrchr(s, j->startchar); + if(p == 0 || s == j->reol) + return match; + s = p; break; case BOL: if(s == bol) break; - while(*s != '\n') { - if(*s == 0 || s == j->reol) - return match; - s++; - } + p = runestrchr(s, '\n'); + if(p == 0 || s == j->reol) + return match; + s = p+1; break; } }