Correct boundary condition error in D' and P' commands when the last

line of the pattern space is empty. Don't emit spurious newline when
EOF is reached with the `N' command.

Pointed out by:	Oleg Osyka
MFC after:	1 week
This commit is contained in:
Tim J. Robbins 2002-08-11 09:53:44 +00:00
parent 6854d13abc
commit 13ee49d316
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=101668

View File

@ -137,7 +137,7 @@ process()
if (pd)
goto new;
if (psl == 0 ||
(p = memchr(ps, '\n', psl - 1)) == NULL) {
(p = memchr(ps, '\n', psl)) == NULL) {
pd = 1;
goto new;
} else {
@ -176,11 +176,8 @@ process()
case 'N':
flush_appends();
cspace(&PS, "\n", 1, 0);
if (!mf_fgets(&PS, 0)) {
if (!nflag && !pd)
OUT(ps)
if (!mf_fgets(&PS, 0))
exit(0);
}
break;
case 'p':
if (pd)
@ -191,7 +188,7 @@ process()
if (pd)
break;
if (psl != 0 &&
(p = memchr(ps, '\n', psl - 1)) != NULL) {
(p = memchr(ps, '\n', psl)) != NULL) {
oldpsl = psl;
psl = p - ps;
}