summaryrefslogtreecommitdiff
path: root/src/grep.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@fb.com>2020-09-18 12:37:17 -0700
committerJim Meyering <meyering@fb.com>2020-09-18 12:45:17 -0700
commit203ad5b718ce349efa6bfa847b356d47dc5c584e (patch)
tree8d1d70e806b9196dc44cce977fd348267ac71c9c /src/grep.c
parent97cc60acf8d4ca48bf310a8bb123d0f8cefc1b99 (diff)
downloadgrep-203ad5b718ce349efa6bfa847b356d47dc5c584e.tar.gz
grep: make echo .|grep '\.' match once again
The same applied for many other backslash-escaped bytes, not just metacharacters. The switch to rawmemchr in v3.4-almost-10-g9393b97 made some parts of the code require the usually-guaranteed newline sentinel at the end of each pattern. Before, some consumers used a (correct) pattern length and did not care that try_fgrep_pattern could transform a pattern (with sentinel) like "\\.\n" to "..\n", thus violating that assumption. * src/grep.c (try_fgrep_pattern): Preserve the invariant that each regexp is newline-terminated. * tests/backslash-dot: New file. Test for this. * tests/Makefile.am (TESTS): Add it.
Diffstat (limited to 'src/grep.c')
-rw-r--r--src/grep.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/grep.c b/src/grep.c
index ba6b15d6..497780e3 100644
--- a/src/grep.c
+++ b/src/grep.c
@@ -2471,6 +2471,9 @@ try_fgrep_pattern (int matcher, char *keys, size_t *len_p)
{
*len_p = p - new_keys;
memcpy (keys, new_keys, p - new_keys);
+ /* We have just shortened this pattern.
+ Preserve the invariant that it is newline-terminated. */
+ keys[*len_p] = '\n';
}
result = F_MATCHER_INDEX;