diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/sed.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c index 30ab8c9fb..4bd6e0168 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 | ||
@@ -560,7 +562,7 @@ static void add_cmd(const char *cmdstr) | |||
560 | /* last part (mandatory) will be a command */ | 562 | /* last part (mandatory) will be a command */ |
561 | if (!*cmdstr) | 563 | if (!*cmdstr) |
562 | bb_error_msg_and_die("missing command"); | 564 | bb_error_msg_and_die("missing command"); |
563 | sed_cmd->cmd = *(cmdstr++); | 565 | sed_cmd->cmd = *cmdstr++; |
564 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); | 566 | cmdstr = parse_cmd_args(sed_cmd, cmdstr); |
565 | 567 | ||
566 | /* Add the command to the command array */ | 568 | /* Add the command to the command array */ |