← Commit list

c3295d233

Gray Wolf
Gray Wolf
2020-04-29
SUCCESS Duration: 153s

Subject

grep: Fix -f FILE when FILE is empty and -x provided

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

findutils/grep.c+3 -2
@@ -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;
}
}
testsuite/grep.tests+6 -0
@@ -129,6 +129,12 @@ testing "grep -v -f EMPTY_FILE" \
"" \
"test\n"
+testing "grep -vxf EMPTY_FILE" \
+ "grep -vxf input" \
+ "test\n" \
+ "" \
+ "test\n"
+
testing "grep -Fw matches only words" \
"grep -Fw foo input" \
"" \