diff options
author | Matt Kraai <kraai@debian.org> | 2001-08-20 21:21:06 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2001-08-20 21:21:06 +0000 |
commit | a3e4f455ac0265d9f2477300054f504f563b0c58 (patch) | |
tree | 96448b8b00f4d257a9820963635044ef93935d75 | |
parent | 54eceffcae3ebf1664e54ba2b32298856a2c4930 (diff) | |
download | busybox-w32-a3e4f455ac0265d9f2477300054f504f563b0c58.tar.gz busybox-w32-a3e4f455ac0265d9f2477300054f504f563b0c58.tar.bz2 busybox-w32-a3e4f455ac0265d9f2477300054f504f563b0c58.zip |
Fix a problem with unsatisfied backrefs (noted by Martin Bene).
-rw-r--r-- | editors/sed.c | 10 | ||||
-rw-r--r-- | sed.c | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/editors/sed.c b/editors/sed.c index a18cfc7c3..352c5c94f 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -490,7 +490,7 @@ static void load_cmd_file(char *filename) | |||
490 | } | 490 | } |
491 | } | 491 | } |
492 | 492 | ||
493 | static void print_subst_w_backrefs(const char *line, const char *replace, regmatch_t *regmatch) | 493 | static void print_subst_w_backrefs(const char *line, const char *replace, regmatch_t *regmatch, int matches) |
494 | { | 494 | { |
495 | int i; | 495 | int i; |
496 | 496 | ||
@@ -506,8 +506,9 @@ static void print_subst_w_backrefs(const char *line, const char *replace, regmat | |||
506 | tmpstr[1] = 0; | 506 | tmpstr[1] = 0; |
507 | backref = atoi(tmpstr); | 507 | backref = atoi(tmpstr); |
508 | /* print out the text held in regmatch[backref] */ | 508 | /* print out the text held in regmatch[backref] */ |
509 | for (j = regmatch[backref].rm_so; j < regmatch[backref].rm_eo; j++) | 509 | if (backref <= matches && regmatch[backref].rm_so != -1) |
510 | fputc(line[j], stdout); | 510 | for (j = regmatch[backref].rm_so; j < regmatch[backref].rm_eo; j++) |
511 | fputc(line[j], stdout); | ||
511 | } | 512 | } |
512 | 513 | ||
513 | /* if we find a backslash escaped character, print the character */ | 514 | /* if we find a backslash escaped character, print the character */ |
@@ -555,7 +556,8 @@ static int do_subst_command(const struct sed_cmd *sed_cmd, const char *line) | |||
555 | fputc(hackline[i], stdout); | 556 | fputc(hackline[i], stdout); |
556 | 557 | ||
557 | /* then print the substitution string */ | 558 | /* then print the substitution string */ |
558 | print_subst_w_backrefs(hackline, sed_cmd->replace, regmatch); | 559 | print_subst_w_backrefs(hackline, sed_cmd->replace, regmatch, |
560 | sed_cmd->num_backrefs); | ||
559 | 561 | ||
560 | /* advance past the match */ | 562 | /* advance past the match */ |
561 | hackline += regmatch[0].rm_eo; | 563 | hackline += regmatch[0].rm_eo; |
@@ -490,7 +490,7 @@ static void load_cmd_file(char *filename) | |||
490 | } | 490 | } |
491 | } | 491 | } |
492 | 492 | ||
493 | static void print_subst_w_backrefs(const char *line, const char *replace, regmatch_t *regmatch) | 493 | static void print_subst_w_backrefs(const char *line, const char *replace, regmatch_t *regmatch, int matches) |
494 | { | 494 | { |
495 | int i; | 495 | int i; |
496 | 496 | ||
@@ -506,8 +506,9 @@ static void print_subst_w_backrefs(const char *line, const char *replace, regmat | |||
506 | tmpstr[1] = 0; | 506 | tmpstr[1] = 0; |
507 | backref = atoi(tmpstr); | 507 | backref = atoi(tmpstr); |
508 | /* print out the text held in regmatch[backref] */ | 508 | /* print out the text held in regmatch[backref] */ |
509 | for (j = regmatch[backref].rm_so; j < regmatch[backref].rm_eo; j++) | 509 | if (backref <= matches && regmatch[backref].rm_so != -1) |
510 | fputc(line[j], stdout); | 510 | for (j = regmatch[backref].rm_so; j < regmatch[backref].rm_eo; j++) |
511 | fputc(line[j], stdout); | ||
511 | } | 512 | } |
512 | 513 | ||
513 | /* if we find a backslash escaped character, print the character */ | 514 | /* if we find a backslash escaped character, print the character */ |
@@ -555,7 +556,8 @@ static int do_subst_command(const struct sed_cmd *sed_cmd, const char *line) | |||
555 | fputc(hackline[i], stdout); | 556 | fputc(hackline[i], stdout); |
556 | 557 | ||
557 | /* then print the substitution string */ | 558 | /* then print the substitution string */ |
558 | print_subst_w_backrefs(hackline, sed_cmd->replace, regmatch); | 559 | print_subst_w_backrefs(hackline, sed_cmd->replace, regmatch, |
560 | sed_cmd->num_backrefs); | ||
559 | 561 | ||
560 | /* advance past the match */ | 562 | /* advance past the match */ |
561 | hackline += regmatch[0].rm_eo; | 563 | hackline += regmatch[0].rm_eo; |