From owner-freebsd-standards@FreeBSD.ORG Tue Jun 3 08:19:27 2003 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 24D8837B401; Tue, 3 Jun 2003 08:19:27 -0700 (PDT) Received: from chiark.greenend.org.uk (chiark.greenend.org.uk [193.201.200.170]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C66043F85; Tue, 3 Jun 2003 08:19:26 -0700 (PDT) (envelope-from fanf@chiark.greenend.org.uk) Received: by chiark.greenend.org.uk (Debian Exim 3.35 #1) with local id 19NDZN-0004WU-00; Tue, 03 Jun 2003 16:19:25 +0100 Date: Tue, 3 Jun 2003 16:19:25 +0100 From: Tony Finch To: freebsd-standards@freebsd.org, tjr@freebsd.org Message-ID: <20030603151925.GI18938@chiark.greenend.org.uk> References: <20030603144225.GH18938@chiark.greenend.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030603144225.GH18938@chiark.greenend.org.uk> User-Agent: Mutt/1.3.28i Sender: Tony Finch Subject: [PATCH] for review Re: Sed substitution bugs X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 03 Jun 2003 15:19:27 -0000 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 http://dotat.at/ SHANNON: VARIABLE 3 BECOMING SOUTHERLY 5 OR 6. SHOWERS. GOOD.