Date: Tue, 3 Jun 2003 16:19:25 +0100 From: Tony Finch <dot@dotat.at> To: freebsd-standards@freebsd.org, tjr@freebsd.org Subject: [PATCH] for review Re: Sed substitution bugs Message-ID: <20030603151925.GI18938@chiark.greenend.org.uk> In-Reply-To: <20030603144225.GH18938@chiark.greenend.org.uk> References: <20030603144225.GH18938@chiark.greenend.org.uk>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jun 03, 2003 at 03:42:25PM +0100, Tony Finch wrote: > $ echo foo | sed 's/ */,/g' > ,f,o,o > $ echo foo | sed 's/ */,/3' > ,foo > $ echo foo | sed 's/ */,/4' > ,foo > $ echo foo | sed 's/ */,/5' > ,foo > $ $ echo foo | ./sed 's/ */,/g' ,f,o,o, $ echo foo | ./sed 's/ */,/3' fo,o $ echo foo | ./sed 's/ */,/4' foo, $ echo foo | ./sed 's/ */,/5' foo $ --- process.c 20 Sep 2002 19:40:23 -0000 1.29 +++ process.c 3 Jun 2003 15:11:47 -0000 @@ -323,7 +323,7 @@ { SPACE tspace; regex_t *re; - size_t re_off, slen; + regoff_t re_off, slen; int lastempty, n; char *s; @@ -361,9 +361,6 @@ s += match[0].rm_eo; slen -= match[0].rm_eo; lastempty = 0; - } else if (match[0].rm_so == slen) { - s += match[0].rm_so; - slen = 0; } else { if (match[0].rm_so == 0) cspace(&SS, s, match[0].rm_so + 1, @@ -375,15 +372,19 @@ slen -= match[0].rm_so + 1; lastempty = 1; } - } while (slen > 0 && regexec_e(re, s, REG_NOTBOL, 0, slen)); + } while (slen >= 0 && regexec_e(re, s, REG_NOTBOL, 0, slen)); /* Copy trailing retained string. */ if (slen > 0) cspace(&SS, s, slen, APPEND); break; default: /* Nth occurrence */ 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; + if (slen < 0) + return (0); if (!regexec_e(re, s, REG_NOTBOL, 0, slen)) return (0); } Tony. -- f.a.n.finch <dot@dotat.at> http://dotat.at/ SHANNON: VARIABLE 3 BECOMING SOUTHERLY 5 OR 6. SHOWERS. GOOD.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030603151925.GI18938>