From c3295d233b6a7d924814eec9a5c5999a876daf9e Mon Sep 17 00:00:00 2001 From: Gray Wolf Date: Wed, 29 Apr 2020 15:49:17 +0200 Subject: grep: Fix -f FILE when FILE is empty and -x provided Grep currently special-cased empty pattern file to be the same as pattern file with one empty line (empty pattern). That does mirror how GNU grep behaves, except when -x is provided. In that case .* pattern needs to be used instead. Signed-off-by: Gray Wolf Signed-off-by: Denys Vlasenko --- findutils/grep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'findutils') diff --git a/findutils/grep.c b/findutils/grep.c index 5b8644c36..84a6f7b1c 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -762,8 +762,9 @@ int grep_main(int argc UNUSED_PARAM, char **argv) if (option_mask32 & OPT_f) { load_regexes_from_file(fopt); if (!pattern_head) { /* -f EMPTY_FILE? */ - /* GNU grep treats it as "nothing matches" */ - llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0)); + /* GNU grep treats it as "nothing matches" except when -x */ + const char *data = (option_mask32 & OPT_x) ? ".*" : ""; + llist_add_to(&pattern_head, new_grep_list_data((char*)data, 0)); invert_search ^= 1; } } -- cgit v1.2.3