From owner-svn-src-stable@freebsd.org Mon Aug 14 21:48:51 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C3392DC2452; Mon, 14 Aug 2017 21:48:51 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8CD0B70244; Mon, 14 Aug 2017 21:48:51 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v7ELmoDS078924; Mon, 14 Aug 2017 21:48:50 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7ELmoMo078922; Mon, 14 Aug 2017 21:48:50 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201708142148.v7ELmoMo078922@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Mon, 14 Aug 2017 21:48:50 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/usr.bin/grep X-SVN-Commit-Revision: 322520 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Aug 2017 21:48:51 -0000 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);