# git grep in .

3 messages from 2006-06-20 to 2006-06-21. Participants: Uwe Zeisberger, Junio C Hamano.
Thread: https://gitlist.dev/t/4591

## Uwe Zeisberger, 2006-06-20 16:08

Subject: git grep in .
Message-ID: <20060620160836.GA20153@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/20060620160836.GA20153%40informatik.uni-freiburg.de

```
Hello,

git grep behaves wrongly if I give it . as path to search in.

E.g.

	uzeisberger@io:~/gsrc/git$ git version
	git version 1.4.0

	uzeisberger@io:~/gsrc/git$ git grep git-grep 
	.gitignore:git-grep
	Documentation/git-grep.txt:git-grep(1)
	Documentation/git-grep.txt:git-grep - Print lines matching a pattern
	Documentation/git-grep.txt:'git-grep' [--cached]
	Documentation/git.txt:gitlink:git-grep[1]::
	Makefile:       git-grep$X git-add$X git-rm$X git-rev-list$X \
	builtin-grep.c:"git-grep <option>* <rev>* [-e] <pattern> [<path>...]";

	uzeisberger@io:~/gsrc/git$ git grep git-grep .

	uzeisberger@io:~/gsrc/git$ 

I'd expect that `git grep git-grep .` gives the same results as `git
grep git-grep`.

Best regards
Uwe

-- 
Uwe Zeisberger

exit vi, lesson II:
: w q ! <CR>

NB: write the current file

```

## Uwe Zeisberger, 2006-06-21 09:04

Subject: [PATCH] Fix possible out-of-bounds array access
Message-ID: <20060621090412.GA9267@informatik.uni-freiburg.de>
URL: https://gitlist.dev/e/20060621090412.GA9267%40informatik.uni-freiburg.de
In-Reply-To: <20060620160836.GA20153@informatik.uni-freiburg.de>

```
If match is "", match[-1] is accessed.  Let pathspec_matches return 1 in that
case indicating that "" matches everything.

Incidently this fixes git-grep'ing in ".".

Signed-off-by: Uwe Zeisberger <Uwe_Zeisberger@digi.com>
---

 builtin-grep.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 9806499..f7767bb 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -29,10 +29,11 @@ static int pathspec_matches(const char *
 		int matchlen = strlen(match);
 		const char *cp, *meta;
 
-		if ((matchlen <= namelen) &&
-		    !strncmp(name, match, matchlen) &&
-		    (match[matchlen-1] == '/' ||
-		     name[matchlen] == '\0' || name[matchlen] == '/'))
+		if (!matchlen ||
+		    ((matchlen <= namelen) &&
+		     !strncmp(name, match, matchlen) &&
+		     (match[matchlen-1] == '/' ||
+		      name[matchlen] == '\0' || name[matchlen] == '/')))
 			return 1;
 		if (!fnmatch(match, name, 0))
 			return 1;
-- 
1.4.0

-- 
Uwe Zeisberger

http://www.google.com/search?q=12+mol+in+dozen

```

## Junio C Hamano, 2006-06-21 11:01

Subject: Re: [PATCH] Fix possible out-of-bounds array access
Message-ID: <7vfyhy22nv.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vfyhy22nv.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060621090412.GA9267@informatik.uni-freiburg.de>

```
Thanks.

```
