diff options
author | pfg <pfg@FreeBSD.org> | 2016-06-01 16:53:02 +0000 |
---|---|---|
committer | pfg <pfg@FreeBSD.org> | 2016-06-01 16:53:02 +0000 |
commit | 80c4320260a7e9b4a0152b24deefd4ddf4c66118 (patch) | |
tree | 24ff95edc80759db6d29434f5dec9901eaaafb46 /usr.bin/sed | |
parent | 17c4d27bf86025cc544627261755ff3620343c2a (diff) | |
download | FreeBSD-src-80c4320260a7e9b4a0152b24deefd4ddf4c66118.zip FreeBSD-src-80c4320260a7e9b4a0152b24deefd4ddf4c66118.tar.gz |
sed(1): Fix a mismatch and sync with the OpenBSD's commit.
This was causing some strange behaviour.
Reported by: olivier
Obtained from: OpenBSD (CVS rev. 1.28)
Diffstat (limited to 'usr.bin/sed')
-rw-r--r-- | usr.bin/sed/process.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index 5c883c4..b70a492 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -394,7 +394,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. */ @@ -404,7 +404,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. */ @@ -425,8 +425,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; /* @@ -446,7 +446,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) |