Skip to content

Commit 1ceabab

Browse files
avargitster
authored andcommitted
grep: remove redundant REG_NEWLINE when compiling fixed regex
Remove the redundant REG_NEWLINE regcomp() flag from the code that compiles a fixed-string regular-expression. The REG_NEWLINE causes metacharacters such as "." to match a newline, since the basic_regex_quote_buf() function being called here escapes all metacharacters using REG_NEWLINE is confusing and redundant. The use of this flag was introduced as an unintended emergent property of 793dc67 ("grep/icase: avoid kwsset when -F is specified", 2016-06-25). That change amended the existing regflags, which were initialized to REG_NEWLINE in init_grep_defaults() assuming a subsequent non-fixed regcomp(). Manual testing reveals that this was always redundant, since no flags of any use were inherited from opt->regflags even back then. 793dc67 passes all tests with this on top: diff --git a/grep.c b/grep.c index 627ae3e..89e84ed7fd 100644 --- a/grep.c +++ b/grep.c @@ -407,3 +407,3 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt) basic_regex_quote_buf(&sb, p->pattern); - regflags = opt->regflags & ~REG_EXTENDED; + regflags = 0; if (opt->ignore_case) Since this isn't used for anything and never was, remove it to reduce confusion when reading this code. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 07a3d41 commit 1ceabab

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt)
593593
{
594594
struct strbuf sb = STRBUF_INIT;
595595
int err;
596-
int regflags = REG_NEWLINE;
596+
int regflags = 0;
597597

598598
basic_regex_quote_buf(&sb, p->pattern);
599599
if (opt->ignore_case)

0 commit comments

Comments
 (0)