From owner-svn-src-stable@freebsd.org Tue Aug 22 02:03:02 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 E0731DE6376; Tue, 22 Aug 2017 02:03:02 +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 BD0F36B8A8; Tue, 22 Aug 2017 02:03:02 +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 v7M231Bf032472; Tue, 22 Aug 2017 02:03:01 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v7M231OI032470; Tue, 22 Aug 2017 02:03:01 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201708220203.v7M231OI032470@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 22 Aug 2017 02:03:01 +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: r322777 - in stable/11: contrib/netbsd-tests/usr.bin/grep usr.bin/grep X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: in stable/11: contrib/netbsd-tests/usr.bin/grep usr.bin/grep X-SVN-Commit-Revision: 322777 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: Tue, 22 Aug 2017 02:03:03 -0000 Author: kevans Date: Tue Aug 22 02:03:01 2017 New Revision: 322777 URL: https://svnweb.freebsd.org/changeset/base/322777 Log: MFC r321450: bsdgrep(1): Don't exit before processing every file Given an empty pattern (i.e. grep "" A B), bsdgrep(1) would previously exit() with the appropriate exit code upon encountering an empty file. Likely intended as an optimization, but this behavior is technically incorrect since an empty pattern should match every line. PR: 220924 Approved by: emaste (mentor, blanket MFC) Modified: stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh stable/11/usr.bin/grep/util.c Directory Properties: stable/11/ (props changed) Modified: stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh ============================================================================== --- stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Tue Aug 22 00:10:15 2017 (r322776) +++ stable/11/contrib/netbsd-tests/usr.bin/grep/t_grep.sh Tue Aug 22 02:03:01 2017 (r322777) @@ -667,6 +667,24 @@ mmap_eof_not_eol_body() atf_check -s exit:0 -o not-empty \ env MALLOC_CONF="redzone:true" grep --mmap -e " " test2 } + +atf_test_case matchall +matchall_head() +{ + atf_set "descr" "Check proper behavior of matching all with an empty string" +} +matchall_body() +{ + printf "" > test1 + printf "A" > test2 + printf "A\nB" > test3 + + atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test1 test2 test3 + atf_check -o inline:"test3:A\ntest3:B\ntest2:A\n" grep "" test3 test1 test2 + atf_check -o inline:"test2:A\ntest3:A\ntest3:B\n" grep "" test2 test3 test1 + + atf_check -s exit:1 grep "" test1 +} # End FreeBSD atf_init_test_cases() @@ -707,5 +725,6 @@ atf_init_test_cases() atf_add_test_case badcontext atf_add_test_case mmap atf_add_test_case mmap_eof_not_eol + atf_add_test_case matchall # End FreeBSD } Modified: stable/11/usr.bin/grep/util.c ============================================================================== --- stable/11/usr.bin/grep/util.c Tue Aug 22 00:10:15 2017 (r322776) +++ stable/11/usr.bin/grep/util.c Tue Aug 22 02:03:01 2017 (r322777) @@ -259,16 +259,8 @@ procfile(const char *fn) pc.ln.boff = 0; pc.ln.off += pc.ln.len + 1; if ((pc.ln.dat = grep_fgetln(f, &pc.ln.len)) == NULL || - pc.ln.len == 0) { - if (pc.ln.line_no == 0 && matchall) - /* - * An empty file with an empty pattern and the - * -w flag does not match - */ - exit(matchall && wflag ? 1 : 0); - else - break; - } + pc.ln.len == 0) + break; if (pc.ln.len > 0 && pc.ln.dat[pc.ln.len - 1] == fileeol) --pc.ln.len;