git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/7] grep: use regmatch() for line matching

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
May 13, 2010, 20:41 UTC
Message-ID
<4BEC63EB.2060307@lsrfire.ath.cx>
In-Reply-To
<4BEC6211.2000309@lsrfire.ath.cx>

Use regmatch() in match_one_pattern(), allowing regex matching beyond NUL characters if regexec() supports the flag REG_STARTEND.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 grep.c                 |    2 +-
 t/t7008-grep-binary.sh |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)
diff --git a/grep.c b/grep.c
index 5be72cf..9dd2471 100644
--- a/grep.c
+++ b/grep.c
@@ -422,7 +422,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol,
 	if (p->fixed)
 		hit = !fixmatch(p->pattern, bol, eol, p->ignore_case, pmatch);
 	else
-		hit = !regexec(&p->regexp, bol, 1, pmatch, eflags);
+		hit = !regmatch(&p->regexp, bol, eol, pmatch, eflags);
 
 	if (hit && p->word_regexp) {
 		if ((pmatch[0].rm_so < 0) ||
diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh
index 1143903..d8fde18 100755
--- a/t/t7008-grep-binary.sh
+++ b/t/t7008-grep-binary.sh
@@ -41,4 +41,14 @@ test_expect_success 'git grep -Fi iLE a' '
 	git grep -Fi iLE a
 '
 
+# This test actually passes on platforms where regexec() supports the
+# flag REG_STARTEND.
+test_expect_failure 'git grep ile a' '
+	git grep ile a
+'
+
+test_expect_failure 'git grep .fi a' '
+	git grep .fi a
+'
+
 test_done
-- 
1.7.1
Previous: René Scharfe
Message 10 of 10 in “grep: better support for binary files”
  1. 0/7 grep: better support for binary filesRené Scharfe, May 13, 2010
  2. 1/7 grep: add test script for binary file handlingRené Scharfe, May 13, 2010
  3. 2/7 grep: refactor handling of binary mode optionsRené Scharfe, May 13, 2010
  4. 3/7 grep: --count over binaryRené Scharfe, May 13, 2010
  5. Dmitry PotapovMay 14, 2010
  6. René ScharfeMay 16, 2010
  7. 4/7 grep: use memmem() for fixed string searchRené Scharfe, May 13, 2010
  8. 5/7 grep: continue case insensitive fixed string search after NUL charsRené Scharfe, May 13, 2010
  9. 6/7 grep: add regmatch(), a wrapper for REG_STARTEND handlingRené Scharfe, May 13, 2010
  10. 7/7 grep: use regmatch() for line matchingRené Scharfe, May 13, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.