This trivial change should fix at least 3 similar bugs. All of

them are related to the `c' function's need to know if we are at
the actual end of the address range.  (It must print the text not
earlier than the whole pattern space was deleted.)  It appears the
only sed function with this requirement.

There is `lastaddr' set by applies(), which is to notify the `c'
function, but it can't always help because it's false when we are
hitting the end of file early.  There is also a bug in applies()
due to which `lastaddr' isn't set to true on degenerate ranges such
as `$,$' or `N,$' if N appears the last line number.

Handling early EOF condition in applies() could look more logical,
but it would effectively revert sed to the unreasonable behaviour
rev. 1.26 of main.c fought against, as it would require lastline()
be called for each line within each address range.  So it's better
to call lastline() only if needed by the `c' function.

Together with this change to sed go regression tests for the bugs
fixed (c1-c3).  A basic test of `c' (c0) is also added as it helped
me to spot my own error.

Discussed with:		dds
Tested by:		the regression tests
MFC after:		1 week
This commit is contained in:
Yaroslav Tykhiy 2007-04-01 13:25:03 +00:00
parent e1e5612341
commit 6b8ef68111
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=168211
6 changed files with 28 additions and 2 deletions

View File

@ -0,0 +1,4 @@
foo
foo
foo
foo

View File

@ -0,0 +1,4 @@
input
data
for validation
foo

View File

@ -0,0 +1,3 @@
input
data
foo

View File

@ -0,0 +1,3 @@
input
data
foo

View File

@ -2,7 +2,7 @@
REGRESSION_START($1)
echo '1..11'
echo '1..15'
REGRESSION_TEST(`G', `sed G < regress.in')
REGRESSION_TEST(`P', `sed P < regress.in')
@ -15,5 +15,17 @@ REGRESSION_TEST(`s4', `echo foo | sed s/,*/,/4')
REGRESSION_TEST(`s5', `echo foo | sed s/,*/,/5')
REGRESSION_TEST(`hanoi', `echo ":abcd: : :" | sed -f hanoi.sed')
REGRESSION_TEST(`math', `echo "4+7*3+2^7/3" | sed -f math.sed')
REGRESSION_TEST(`c0', `sed ''`c\
foo
''`< regress.in')
REGRESSION_TEST(`c1', `sed ''`4,$c\
foo
''`< regress.in')
REGRESSION_TEST(`c2', `sed ''`3,9c\
foo
''`< regress.in')
REGRESSION_TEST(`c3', `sed ''`3,/no such string/c\
foo
''`< regress.in')
REGRESSION_END()

View File

@ -128,7 +128,7 @@ process(void)
case 'c':
pd = 1;
psl = 0;
if (cp->a2 == NULL || lastaddr)
if (cp->a2 == NULL || lastaddr || lastline())
(void)fprintf(outfile, "%s", cp->t);
break;
case 'd':