svn commit: r313948 - head/usr.bin/grep
Ed Maste
emaste at FreeBSD.org
Sun Feb 19 17:23:29 UTC 2017
Author: emaste
Date: Sun Feb 19 17:23:27 2017
New Revision: 313948
URL: https://svnweb.freebsd.org/changeset/base/313948
Log:
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
Submitted by: Kyle Evans <kevans91 at ksu.edu>
MFC after: 1 month
Modified:
head/usr.bin/grep/file.c
Modified: head/usr.bin/grep/file.c
==============================================================================
--- head/usr.bin/grep/file.c Sun Feb 19 17:17:06 2017 (r313947)
+++ head/usr.bin/grep/file.c Sun Feb 19 17:23:27 2017 (r313948)
@@ -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);
More information about the svn-src-all
mailing list