Don't forget to close the range if we branched over its end

and had no chance to match it by the 2nd address precisely.
Otherwise the unclosed range would bogusly extend to the end
of stream.

Add a basic regression test for the bug fixed.  (This change
also fixes the more complex case 5.3 from `multitest.t'.)

Compared with:	SUN and GNU seds
Tested by:	regression tests
MFC after:	1 week
This commit is contained in:
yar 2007-04-02 08:14:46 +00:00
parent 03cf2678d2
commit d1f2d71a20
3 changed files with 17 additions and 3 deletions

View File

@ -0,0 +1,3 @@
data
for validation
of sed(1)

View File

@ -2,7 +2,7 @@
REGRESSION_START($1)
echo '1..15'
echo '1..16'
REGRESSION_TEST(`G', `sed G < regress.in')
REGRESSION_TEST(`P', `sed P < regress.in')
@ -27,5 +27,7 @@ foo
REGRESSION_TEST(`c3', `sed ''`3,/no such string/c\
foo
''`< regress.in')
REGRESSION_TEST(`b2a', `sed ''`2,3b
1,2d''` < regress.in')
REGRESSION_END()

View File

@ -285,8 +285,17 @@ applies(struct s_command *cp)
if (MATCH(cp->a2)) {
cp->inrange = 0;
lastaddr = 1;
}
r = 1;
r = 1;
} else if (cp->a2->type == AT_LINE &&
linenum > cp->a2->u.l) {
/*
* We missed the 2nd address due to a branch,
* so just close the range and return false.
*/
cp->inrange = 0;
r = 0;
} else
r = 1;
} else if (MATCH(cp->a1)) {
/*
* If the second address is a number less than or