mirror of
https://git.FreeBSD.org/src.git
synced 2025-02-05 18:05:16 +00:00
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 Reviewed by: emaste, cem (earlier version), ngie Approved by: emaste (mentor) Differential Revision: https://reviews.freebsd.org/D11698
This commit is contained in:
parent
fcb60eb0bb
commit
0e95794283
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=321450
@ -669,6 +669,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()
|
||||
@ -709,5 +727,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
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user