diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/sed.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/editors/sed.c b/editors/sed.c index fd9dd1be6..4289aa646 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -487,7 +487,7 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr) | |||
487 | static void add_cmd(const char *cmdstr) | 487 | static void add_cmd(const char *cmdstr) |
488 | { | 488 | { |
489 | sed_cmd_t *sed_cmd; | 489 | sed_cmd_t *sed_cmd; |
490 | int temp; | 490 | unsigned len, n; |
491 | 491 | ||
492 | /* Append this line to any unfinished line from last time. */ | 492 | /* Append this line to any unfinished line from last time. */ |
493 | if (G.add_cmd_line) { | 493 | if (G.add_cmd_line) { |
@@ -496,12 +496,14 @@ static void add_cmd(const char *cmdstr) | |||
496 | cmdstr = G.add_cmd_line = tp; | 496 | cmdstr = G.add_cmd_line = tp; |
497 | } | 497 | } |
498 | 498 | ||
499 | /* If this line ends with backslash, request next line. */ | 499 | /* If this line ends with unescaped backslash, request next line. */ |
500 | temp = strlen(cmdstr); | 500 | n = len = strlen(cmdstr); |
501 | if (temp && cmdstr[--temp] == '\\') { | 501 | while (n && cmdstr[n-1] == '\\') |
502 | n--; | ||
503 | if ((len - n) & 1) { /* if odd number of trailing backslashes */ | ||
502 | if (!G.add_cmd_line) | 504 | if (!G.add_cmd_line) |
503 | G.add_cmd_line = xstrdup(cmdstr); | 505 | G.add_cmd_line = xstrdup(cmdstr); |
504 | G.add_cmd_line[temp] = '\0'; | 506 | G.add_cmd_line[len-1] = '\0'; |
505 | return; | 507 | return; |
506 | } | 508 | } |
507 | 509 | ||
@@ -936,7 +938,15 @@ static void process_files(void) | |||
936 | /* Skip blocks of commands we didn't match */ | 938 | /* Skip blocks of commands we didn't match */ |
937 | if (sed_cmd->cmd == '{') { | 939 | if (sed_cmd->cmd == '{') { |
938 | if (sed_cmd->invert ? matched : !matched) { | 940 | if (sed_cmd->invert ? matched : !matched) { |
939 | while (sed_cmd->cmd != '}') { | 941 | unsigned nest_cnt = 0; |
942 | while (1) { | ||
943 | if (sed_cmd->cmd == '{') | ||
944 | nest_cnt++; | ||
945 | if (sed_cmd->cmd == '}') { | ||
946 | nest_cnt--; | ||
947 | if (nest_cnt == 0) | ||
948 | break; | ||
949 | } | ||
940 | sed_cmd = sed_cmd->next; | 950 | sed_cmd = sed_cmd->next; |
941 | if (!sed_cmd) | 951 | if (!sed_cmd) |
942 | bb_error_msg_and_die("unterminated {"); | 952 | bb_error_msg_and_die("unterminated {"); |
@@ -1031,7 +1041,7 @@ static void process_files(void) | |||
1031 | case 'c': | 1041 | case 'c': |
1032 | /* Only triggers on last line of a matching range. */ | 1042 | /* Only triggers on last line of a matching range. */ |
1033 | if (!sed_cmd->in_match) | 1043 | if (!sed_cmd->in_match) |
1034 | sed_puts(sed_cmd->string, NO_EOL_CHAR); | 1044 | sed_puts(sed_cmd->string, '\n'); |
1035 | goto discard_line; | 1045 | goto discard_line; |
1036 | 1046 | ||
1037 | /* Read file, append contents to output */ | 1047 | /* Read file, append contents to output */ |