aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-06-08 10:25:31 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-06-08 10:25:31 +0200
commit37ca36a71114a6fc5303d33cabc311cd8b9bf19a (patch)
tree28f9108375b2dc4050d447995f3fe497315d3d39 /editors
parentba1d561d767a6f05da62adadc798f98118b2a3ee (diff)
downloadbusybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.tar.gz
busybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.tar.bz2
busybox-w32-37ca36a71114a6fc5303d33cabc311cd8b9bf19a.zip
sed: yet another fix on top of zero length match code
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 0fe82f337..652aaf573 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)
768 * Second match is NOT replaced! 768 * Second match is NOT replaced!
769 */ 769 */
770 if (prev_match_empty || start != 0 || start != end) { 770 if (prev_match_empty || start != 0 || start != end) {
771 //dbg("%d %d %d", prev_match_empty, start, end);
771 dbg("inserting replacement at %d in '%s'", start, line); 772 dbg("inserting replacement at %d in '%s'", start, line);
772 do_subst_w_backrefs(line, sed_cmd->string); 773 do_subst_w_backrefs(line, sed_cmd->string);
774 /* Flag that something has changed */
775 altered = 1;
773 } else { 776 } else {
774 dbg("NOT inserting replacement at %d in '%s'", start, line); 777 dbg("NOT inserting replacement at %d in '%s'", start, line);
775 } 778 }
@@ -778,16 +781,18 @@ static int do_subst_command(sed_cmd_t *sed_cmd, char **line_p)
778 * copy verbatim one char after it before attempting more matches 781 * copy verbatim one char after it before attempting more matches
779 */ 782 */
780 prev_match_empty = (start == end); 783 prev_match_empty = (start == end);
781 if (prev_match_empty && line[end]) { 784 if (prev_match_empty) {
782 pipe_putc(line[end]); 785 if (!line[end]) {
783 end++; 786 tried_at_eol = 1;
787 } else {
788 pipe_putc(line[end]);
789 end++;
790 }
784 } 791 }
785 792
786 /* Advance past the match */ 793 /* Advance past the match */
787 dbg("line += %d", end); 794 dbg("line += %d", end);
788 line += end; 795 line += end;
789 /* Flag that something has changed */
790 altered = 1;
791 796
792 /* if we're not doing this globally, get out now */ 797 /* if we're not doing this globally, get out now */
793 if (sed_cmd->which_match != 0) 798 if (sed_cmd->which_match != 0)