Index: contrib/netbsd-tests/usr.bin/grep/t_grep.sh =================================================================== --- contrib/netbsd-tests/usr.bin/grep/t_grep.sh +++ contrib/netbsd-tests/usr.bin/grep/t_grep.sh @@ -669,6 +669,22 @@ 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 +} # End FreeBSD atf_init_test_cases() @@ -709,5 +725,6 @@ 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 } Index: usr.bin/grep/util.c =================================================================== --- usr.bin/grep/util.c +++ usr.bin/grep/util.c @@ -260,14 +260,9 @@ 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; + if (pc.ln.line_no == 0 && matchall && !wflag) + ++c; + break; } if (pc.ln.len > 0 && pc.ln.dat[pc.ln.len - 1] == fileeol)