aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-09-16 01:11:13 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-09-16 01:11:13 +0200
commit9caea2448e168560de306a1496574dd58c645fea (patch)
tree33c156525649779bfcff3a5f0b9711a23704dbf6
parent7666fa1d02b4e7e74a83833881caef09b475b88b (diff)
downloadbusybox-w32-9caea2448e168560de306a1496574dd58c645fea.tar.gz
busybox-w32-9caea2448e168560de306a1496574dd58c645fea.tar.bz2
busybox-w32-9caea2448e168560de306a1496574dd58c645fea.zip
sed: fix a buglet in s///NUM handling
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--editors/sed.c5
-rwxr-xr-xtestsuite/sed.tests4
2 files changed, 8 insertions, 1 deletions
diff --git a/editors/sed.c b/editors/sed.c
index e18e48ab5..e1b8352fd 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -395,7 +395,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
395 /* process the flags */ 395 /* process the flags */
396 396
397 sed_cmd->which_match = 1; 397 sed_cmd->which_match = 1;
398 dbg("s flags:'%s'", substr + idx + 1);
398 while (substr[++idx]) { 399 while (substr[++idx]) {
400 dbg("s flag:'%c'", substr[idx]);
399 /* Parse match number */ 401 /* Parse match number */
400 if (isdigit(substr[idx])) { 402 if (isdigit(substr[idx])) {
401 if (match[0] != '^') { 403 if (match[0] != '^') {
@@ -403,7 +405,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
403 const char *pos = substr + idx; 405 const char *pos = substr + idx;
404/* FIXME: error check? */ 406/* FIXME: error check? */
405 sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10); 407 sed_cmd->which_match = (unsigned)strtol(substr+idx, (char**) &pos, 10);
406 idx = pos - substr; 408 idx = pos - substr - 1;
407 } 409 }
408 continue; 410 continue;
409 } 411 }
@@ -443,6 +445,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
443 case '}': 445 case '}':
444 goto out; 446 goto out;
445 default: 447 default:
448 dbg("s bad flags:'%s'", substr + idx);
446 bb_error_msg_and_die("bad option in substitution expression"); 449 bb_error_msg_and_die("bad option in substitution expression");
447 } 450 }
448 } 451 }
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index 9494ac2de..19f2915ce 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -329,6 +329,10 @@ line with \\
329continuation 329continuation
330" 330"
331 331
332testing "sed s///NUM test" \
333 "sed -e 's/a/b/2; s/a/c/g'" \
334 "cb\n" "" "aa\n"
335
332# testing "description" "commands" "result" "infile" "stdin" 336# testing "description" "commands" "result" "infile" "stdin"
333 337
334exit $FAILCOUNT 338exit $FAILCOUNT