Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Aug 2017 02:03:01 +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: r322777 - in stable/11: contrib/netbsd-tests/usr.bin/grep usr.bin/grep
Message-ID:  <201708220203.v7M231OI032470@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



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