summaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
authorDenys Vlasenko2012-06-08 10:25:31 +0200
committerDenys Vlasenko2012-06-08 10:25:31 +0200
commit37ca36a71114a6fc5303d33cabc311cd8b9bf19a (patch)
tree28f9108375b2dc4050d447995f3fe497315d3d39 /editors/sed.c
parentba1d561d767a6f05da62adadc798f98118b2a3ee (diff)
downloadbusybox-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.zip
busybox-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.tar.gz
sed: yet another fix on top of zero length match code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors/sed.c')
-rw-r--r--editors/sed.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 0fe82f3..652aaf5 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -768,8 +768,11 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
* Second match is NOT replaced!
*/
if (prev_match_empty || start != 0 || start != end) {
+ //dbg("%d %d %d", prev_match_empty, start, end);
dbg("inserting replacement at %d in '%s'", start, line);
do_subst_w_backrefs(line, sed_cmd->string);
+ /* Flag that something has changed */
+ altered = 1;
} else {
dbg("NOT inserting replacement at %d in '%s'", start, line);
}
@@ -778,16 +781,18 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
* copy verbatim one char after it before attempting more matches
*/
prev_match_empty = (start == end);
- if (prev_match_empty && line[end]) {
- pipe_putc(line[end]);
- end++;
+ if (prev_match_empty) {
+ if (!line[end]) {
+ tried_at_eol = 1;
+ } else {
+ pipe_putc(line[end]);
+ end++;
+ }
}
/* Advance past the match */
dbg("line += %d", end);
line += end;
- /* Flag that something has changed */
- altered = 1;
/* if we're not doing this globally, get out now */
if (sed_cmd->which_match != 0)