diff options
author | yar <yar@FreeBSD.org> | 2007-06-12 12:05:24 +0000 |
---|---|---|
committer | yar <yar@FreeBSD.org> | 2007-06-12 12:05:24 +0000 |
commit | 64e06b67c3cf285a62f1f8cdbed2f005b02418a1 (patch) | |
tree | 1fc5aa0c7aed36e9c671f4752d0a3f9b2ac0c3fd /usr.bin/sed | |
parent | 36ecaa8cd6cf4939ee6d5692193c12bf400fcbf6 (diff) | |
download | FreeBSD-src-64e06b67c3cf285a62f1f8cdbed2f005b02418a1.zip FreeBSD-src-64e06b67c3cf285a62f1f8cdbed2f005b02418a1.tar.gz |
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
Diffstat (limited to 'usr.bin/sed')
-rw-r--r-- | usr.bin/sed/extern.h | 2 | ||||
-rw-r--r-- | usr.bin/sed/main.c | 2 | ||||
-rw-r--r-- | usr.bin/sed/process.c | 18 |
3 files changed, 18 insertions, 4 deletions
diff --git a/usr.bin/sed/extern.h b/usr.bin/sed/extern.h index cb4ae16..f2bd71b 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 e4e426f..e17741f 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 c8b62c0..ca21ec7 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -234,6 +234,12 @@ redirect: 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); } /* |