Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Aug 2017 21:48:50 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r322520 - stable/11/usr.bin/grep
Message-ID:  <201708142148.v7ELmoMo078922@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Aug 14 21:48:50 2017
New Revision: 322520
URL: https://svnweb.freebsd.org/changeset/base/322520

Log:
  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)

Modified:
  stable/11/usr.bin/grep/file.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.bin/grep/file.c
==============================================================================
--- stable/11/usr.bin/grep/file.c	Mon Aug 14 20:53:01 2017	(r322519)
+++ stable/11/usr.bin/grep/file.c	Mon Aug 14 21:48:50 2017	(r322520)
@@ -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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201708142148.v7ELmoMo078922>