summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-06-28 03:11:07 +0000
committerpfg <pfg@FreeBSD.org>2016-06-28 03:11:07 +0000
commitc912a7ae2b2e85f6a4660fdb2773854e53eddc43 (patch)
tree80aca3304290d7e3ee61725c473ccbd964fd8286 /usr.bin
parent19f52205250ba3154d3fea21f7139ad3f4c16cda (diff)
downloadFreeBSD-src-c912a7ae2b2e85f6a4660fdb2773854e53eddc43.zip
FreeBSD-src-c912a7ae2b2e85f6a4660fdb2773854e53eddc43.tar.gz
MFC r301138:
sed(1): convert sed to use REG_STARTEND more explicitly. This is a followup to previous r302228, which only merged the incomplete r300684 causing a regression. Reported by: mi PR: 209387 Taken from: openbsd-tech (Martijn van Duren)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/sed/process.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c
index b9c25c0..891a7ce 100644
--- a/usr.bin/sed/process.c
+++ b/usr.bin/sed/process.c
@@ -384,7 +384,7 @@ substitute(struct s_command *cp)
linenum, fname, cp->u.s->maxbref);
}
}
- if (!regexec_e(re, s, 0, 0, 0, psl))
+ if (!regexec_e(re, ps, 0, 0, 0, psl))
return (0);
SS.len = 0; /* Clean substitute space. */
@@ -394,7 +394,7 @@ substitute(struct s_command *cp)
do {
/* Copy the leading retained string. */
- if (n <= 1 && match[0].rm_so - le)
+ if (n <= 1 && (match[0].rm_so > le))
cspace(&SS, s, match[0].rm_so - le, APPEND);
/* Skip zero-length matches right after other matches. */
@@ -415,8 +415,8 @@ substitute(struct s_command *cp)
}
/* Move past this match. */
- s += (match[0].rm_eo - le);
- slen -= (match[0].rm_eo - le);
+ s = ps + match[0].rm_eo;
+ slen = psl - match[0].rm_eo;
le = match[0].rm_eo;
/*
@@ -436,7 +436,8 @@ substitute(struct s_command *cp)
} else
lastempty = 0;
- } while (n >= 0 && slen >= 0 && regexec_e(re, ps, 0, 0, le, psl));
+ } while (n >= 0 && slen >= 0 &&
+ regexec_e(re, ps, REG_NOTBOL, 0, le, psl));
/* Did not find the requested number of matches. */
if (n > 1)
OpenPOWER on IntegriCloud