Don't forget to clear out the hold space for each subsequent file
when in -i mode so that each file gets a clean context of its own. Add a regression test for the bug. Tested with: regression tests
This commit is contained in:
parent
7cd3f6159b
commit
26a5710c40
@ -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')
|
||||
|
@ -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 *);
|
||||
|
@ -390,7 +390,7 @@ mf_fgets(SPACE *sp, enum e_spflag spflag)
|
||||
outfname = tmpfname;
|
||||
if (!ispan) {
|
||||
linenum = 0;
|
||||
resetranges();
|
||||
resetstate();
|
||||
}
|
||||
} else {
|
||||
outfile = stdout;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user