diff --git a/tools/regression/usr.bin/sed/regress.sh b/tools/regression/usr.bin/sed/regress.sh index 2820a2516cfe..520abd5c7bc9 100644 --- a/tools/regression/usr.bin/sed/regress.sh +++ b/tools/regression/usr.bin/sed/regress.sh @@ -2,7 +2,7 @@ REGRESSION_START($1) -echo '1..20' +echo '1..21' REGRESSION_TEST(`G', `sed G < regress.in') REGRESSION_TEST(`P', `sed P < regress.in') @@ -61,6 +61,7 @@ REGRESSION_TEST_FREEFORM(`inplace1', `inplace_test 3,6d') REGRESSION_TEST_FREEFORM(`inplace2', `inplace_test 8,30d') REGRESSION_TEST_FREEFORM(`inplace3', `inplace_test 20,99d') REGRESSION_TEST_FREEFORM(`inplace4', `inplace_test "{;{;8,30d;};}"') +REGRESSION_TEST_FREEFORM(`inplace5', `inplace_test "3x;6G"') REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f hanoi.sed') REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f math.sed') diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h index cb4ae163853f..f2bd71bacfa4 100644 --- a/usr.bin/sed/extern.h +++ b/usr.bin/sed/extern.h @@ -52,5 +52,5 @@ char *cu_fgets(char *, int, int *); int mf_fgets(SPACE *, enum e_spflag); int lastline(void); void process(void); -void resetranges(void); +void resetstate(void); char *strregerror(int, regex_t *); diff --git a/usr.bin/sed/main.c b/usr.bin/sed/main.c index e4e426f7c7db..e17741f6257d 100644 --- a/usr.bin/sed/main.c +++ b/usr.bin/sed/main.c @@ -390,7 +390,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag) outfname = tmpfname; if (!ispan) { linenum = 0; - resetranges(); + resetstate(); } } else { outfile = stdout; diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index c8b62c095dbd..ca21ec7e66b9 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -234,6 +234,12 @@ process(void) err(1, "%s", cp->t); break; case 'x': + /* + * If the hold space is null, make it empty + * but not null. Otherwise the pattern space + * will become null after the swap, which is + * an abnormal condition. + */ if (hs == NULL) cspace(&HS, "", 0, REPLACE); tspace = PS; @@ -317,16 +323,24 @@ applies(struct s_command *cp) } /* - * Reset all inrange markers. + * Reset the sed processor to its initial state. */ void -resetranges(void) +resetstate(void) { struct s_command *cp; + /* + * Reset all inrange markers. + */ for (cp = prog; cp; cp = cp->code == '{' ? cp->u.c : cp->next) if (cp->a2) cp->inrange = 0; + + /* + * Clear out the hold space. + */ + cspace(&HS, "", 0, REPLACE); } /*