summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorkevans <kevans@FreeBSD.org>2017-08-14 21:48:50 +0000
committerkevans <kevans@FreeBSD.org>2017-08-14 21:48:50 +0000
commit03a37e0a48ec05481519ea016980e20a34455673 (patch)
tree2c23471525b802c6bdaa3b6ce00771ccd43961f2 /usr.bin
parentcda5653328ddfb4773a6dcb31e9f15e27d5afa6d (diff)
downloadFreeBSD-src-03a37e0a48ec05481519ea016980e20a34455673.zip
FreeBSD-src-03a37e0a48ec05481519ea016980e20a34455673.tar.gz
MFC r313948: bsdgrep: fix EOF handling with --mmap
Rework part of the loop in grep_fgetln to return the rest of the line and ensure that we still advance the buffer by the length of the rest of the line. PR: 165471 Approved by: emaste (mentor)
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/grep/file.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/grep/file.c b/usr.bin/grep/file.c
index 81f227d..34831f1 100644
--- a/usr.bin/grep/file.c
+++ b/usr.bin/grep/file.c
@@ -219,12 +219,18 @@ grep_fgetln(struct file *f, size_t *lenp)
if (bufrem == 0)
/* EOF: return partial line */
break;
- if ((p = memchr(bufpos, '\n', bufrem)) == NULL)
+ if ((p = memchr(bufpos, '\n', bufrem)) == NULL &&
+ filebehave != FILE_MMAP)
continue;
- /* got it: finish up the line (like code above) */
- ++p;
- diff = p - bufpos;
- len += diff;
+ if (p == NULL) {
+ /* mmap EOF: return partial line, consume buffer */
+ diff = len;
+ } else {
+ /* got it: finish up the line (like code above) */
+ ++p;
+ diff = p - bufpos;
+ len += diff;
+ }
if (grep_lnbufgrow(len))
goto error;
memcpy(lnbuf + off, bufpos, diff);
OpenPOWER on IntegriCloud