diff --git a/usr.bin/sed/process.c b/usr.bin/sed/process.c index ff3cb1913889..a1e3ca72756c 100644 --- a/usr.bin/sed/process.c +++ b/usr.bin/sed/process.c @@ -136,7 +136,8 @@ redirect: case 'D': if (pd) goto new; - if ((p = memchr(ps, '\n', psl - 1)) == NULL) { + if (psl == 0 || + (p = memchr(ps, '\n', psl - 1)) == NULL) { pd = 1; goto new; } else { @@ -188,7 +189,8 @@ redirect: case 'P': if (pd) break; - if ((p = memchr(ps, '\n', psl - 1)) != NULL) { + if (psl != 0 && + (p = memchr(ps, '\n', psl - 1)) != NULL) { oldpsl = psl; psl = (p + 1) - ps; } @@ -240,7 +242,7 @@ redirect: HS = tspace; break; case 'y': - if (pd) + if (pd || psl == 0) break; for (p = ps, len = psl; --len; ++p) *p = cp->u.y[(unsigned char)*p];