sed: fix a buglet in s///NUM handling

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2014-09-16 01:11:13 +02:00
parent 7666fa1d02
commit 9caea2448e
2 changed files with 8 additions and 1 deletions

View File

@ -395,7 +395,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
/* process the flags */ /* process the flags */
sed_cmd->which_match = 1; sed_cmd->which_match = 1;
dbg("s flags:'%s'", substr + idx + 1);
while (substr[++idx]) { while (substr[++idx]) {
dbg("s flag:'%c'", substr[idx]);
/* Parse match number */ /* Parse match number */
if (isdigit(substr[idx])) { if (isdigit(substr[idx])) {
if (match[0] != '^') { if (match[0] != '^') {
@ -403,7 +405,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
const char *pos = substr + idx; const char *pos = substr + idx;
/* FIXME: error check? */ /* FIXME: error check? */
sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10); sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
idx = pos - substr; idx = pos - substr - 1;
} }
continue; continue;
} }
@ -443,6 +445,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
case '}': case '}':
goto out; goto out;
default: default:
dbg("s bad flags:'%s'", substr + idx);
bb_error_msg_and_die("bad option in substitution expression"); bb_error_msg_and_die("bad option in substitution expression");
} }
} }

View File

@ -329,6 +329,10 @@ line with \\
continuation continuation
" "
testing "sed s///NUM test" \
"sed -e 's/a/b/2; s/a/c/g'" \
"cb\n" "" "aa\n"
# testing "description" "commands" "result" "infile" "stdin" # testing "description" "commands" "result" "infile" "stdin"
exit $FAILCOUNT exit $FAILCOUNT