Index: lib/libc/regex/engine.c =================================================================== --- lib/libc/regex/engine.c +++ lib/libc/regex/engine.c @@ -789,7 +789,7 @@ ASSIGN(fresh, st); SP("start", st, *p); coldp = NULL; - if (start == m->beginp) + if (start == m->offp) c = OUT; else { /* @@ -894,7 +894,7 @@ SP("sstart", st, *p); st = step(m->g, startst, stopst, st, NOTHING, st); matchp = NULL; - if (start == m->beginp) + if (start == m->offp) c = OUT; else { /* Index: lib/libc/regex/regcomp.c =================================================================== --- lib/libc/regex/regcomp.c +++ lib/libc/regex/regcomp.c @@ -768,8 +768,10 @@ char c; wint_t start, finish; wint_t i; +#ifndef REDEBUG struct xlocale_collate *table = (struct xlocale_collate*)__get_locale()->components[XLC_COLLATE]; +#endif /* classify what we've got */ switch ((MORE()) ? PEEK() : '\0') { @@ -817,9 +819,12 @@ if (start == finish) CHadd(p, cs, start); else { +#ifndef REDEBUG if (table->__collate_load_error) { +#endif (void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE); CHaddrange(p, cs, start, finish); +#ifndef REDEBUG } else { (void)REQUIRE(__collate_range_cmp(table, start, finish) <= 0, REG_ERANGE); for (i = 0; i <= UCHAR_MAX; i++) { @@ -829,6 +834,7 @@ CHadd(p, cs, i); } } +#endif } break; } Index: usr.bin/sed/process.c =================================================================== --- usr.bin/sed/process.c +++ usr.bin/sed/process.c @@ -71,7 +71,7 @@ static void do_tr(struct s_tr *); static void flush_appends(void); static void lputs(char *, size_t); -static int regexec_e(regex_t *, const char *, int, int, size_t); +static int regexec_e(regex_t *, const char *, int, int, const char *, size_t); static void regsub(SPACE *, char *, char *); static int substitute(struct s_command *); @@ -281,7 +281,7 @@ * (lastline, linenumber, ps). */ #define MATCH(a) \ - ((a)->type == AT_RE ? regexec_e((a)->u.r, ps, 0, 1, psl) : \ + ((a)->type == AT_RE ? regexec_e((a)->u.r, ps, 0, 1, ps, psl) : \ (a)->type == AT_LINE ? linenum == (a)->u.l : lastline()) /* @@ -392,7 +392,7 @@ linenum, fname, cp->u.s->maxbref); } } - if (!regexec_e(re, s, 0, 0, psl)) + if (!regexec_e(re, s, 0, 0, s, psl)) return (0); SS.len = 0; /* Clean substitute space. */ @@ -407,25 +407,25 @@ /* Locate start of replaced string. */ re_off = match[0].rm_so; /* Copy leading retained string. */ - cspace(&SS, s, re_off, APPEND); + cspace(&SS, s, re_off - (s - ps), APPEND); /* Add in regular expression. */ - regsub(&SS, s, cp->u.s->new); + regsub(&SS, ps, cp->u.s->new); } /* Move past this match. */ if (match[0].rm_so != match[0].rm_eo) { - s += match[0].rm_eo; - slen -= match[0].rm_eo; + s = ps + match[0].rm_eo; + slen = psl - match[0].rm_eo; lastempty = 0; } else { - if (match[0].rm_so < slen) - cspace(&SS, s + match[0].rm_so, 1, + if (match[0].rm_so < psl) + cspace(&SS, ps + match[0].rm_so, 1, APPEND); - s += match[0].rm_so + 1; - slen -= match[0].rm_so + 1; + s = ps + match[0].rm_so + 1; + slen = psl - match[0].rm_so - 1; lastempty = 1; } - } while (slen >= 0 && regexec_e(re, s, REG_NOTBOL, 0, slen)); + } while (slen >= 0 && regexec_e(re, ps, REG_NOTBOL, 0, s, slen)); /* Copy trailing retained string. */ if (slen > 0) cspace(&SS, s, slen, APPEND); @@ -434,24 +434,24 @@ while (--n) { if (match[0].rm_eo == match[0].rm_so) match[0].rm_eo = match[0].rm_so + 1; - s += match[0].rm_eo; - slen -= match[0].rm_eo; + s = ps + match[0].rm_eo; + slen = psl - match[0].rm_eo; if (slen < 0) return (0); - if (!regexec_e(re, s, REG_NOTBOL, 0, slen)) + if (!regexec_e(re, ps, REG_NOTBOL, 0, s, slen)) return (0); } /* FALLTHROUGH */ case 1: /* 1st occurrence */ /* Locate start of replaced string. */ - re_off = match[0].rm_so + (s - ps); + re_off = match[0].rm_so; /* Copy leading retained string. */ cspace(&SS, ps, re_off, APPEND); /* Add in regular expression. */ - regsub(&SS, s, cp->u.s->new); + regsub(&SS, ps, cp->u.s->new); /* Copy trailing retained string. */ - s += match[0].rm_eo; - slen -= match[0].rm_eo; + s = ps + match[0].rm_eo; + slen = psl - match[0].rm_eo; cspace(&SS, s, slen, APPEND); break; } @@ -658,7 +658,7 @@ static int regexec_e(regex_t *preg, const char *string, int eflags, int nomatch, - size_t slen) + const char *start, size_t slen) { int eval; @@ -669,8 +669,8 @@ defpreg = preg; /* Set anchors */ - match[0].rm_so = 0; - match[0].rm_eo = slen; + match[0].rm_so = start - string; + match[0].rm_eo = match[0].rm_so + slen; eval = regexec(defpreg, string, nomatch ? 0 : maxnsub + 1, match, eflags | REG_STARTEND);