X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=sed.c;h=24b62e5fab6ba669c26c9f21faa018b5efe22c04;hb=044228d5ecb9b79397f9fc915d046cf4538281e2;hp=73ed058e237fa1a2486bad4d194e74b87d7257f5;hpb=0915c4b98533502b23b8021d0aa7b1a8c7f7ea4f;p=oweals%2Fbusybox.git diff --git a/sed.c b/sed.c index 73ed058e2..24b62e5fa 100644 --- a/sed.c +++ b/sed.c @@ -195,15 +195,6 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *linenum, r return idx; } -static char *strdup_substr(const char *str, int start, int end) -{ - int size = end - start + 1; - char *newstr = xmalloc(size); - memcpy(newstr, str+start, size-1); - newstr[size-1] = '\0'; - return newstr; -} - static int parse_subst_cmd(struct sed_cmd *sed_cmd, const char *substr) { int oldidx, cflags = REG_NEWLINE; @@ -232,7 +223,7 @@ static int parse_subst_cmd(struct sed_cmd *sed_cmd, const char *substr) idx = index_of_next_unescaped_regexp_delim(sed_cmd, substr, ++idx); if (idx == -1) error_msg_and_die("bad format in substitution expression"); - match = strdup_substr(substr, oldidx, idx); + match = xstrndup(substr + oldidx, idx - oldidx); /* determine the number of back references in the match string */ /* Note: we compute this here rather than in the do_subst_command() @@ -251,7 +242,7 @@ static int parse_subst_cmd(struct sed_cmd *sed_cmd, const char *substr) idx = index_of_next_unescaped_regexp_delim(sed_cmd, substr, ++idx); if (idx == -1) error_msg_and_die("bad format in substitution expression"); - sed_cmd->replace = strdup_substr(substr, oldidx, idx); + sed_cmd->replace = xstrndup(substr + oldidx, idx - oldidx); /* process the flags */ while (substr[++idx]) { @@ -608,6 +599,10 @@ static void process_file(FILE *file) * entry point into sedding... */ if ( + /* no range necessary */ + (sed_cmds[i].beg_line == 0 && sed_cmds[i].end_line == 0 && + sed_cmds[i].beg_match == NULL && + sed_cmds[i].end_match == NULL) || /* this line number is the first address we're looking for */ (sed_cmds[i].beg_line && (sed_cmds[i].beg_line == linenum)) || /* this line matches our first address regex */