git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git grep '(' = segfault
@ 2009-04-27 17:46 Dmitry Potapov
  2009-04-27 18:10 ` Linus Torvalds
  2009-04-27 18:15 ` Michał Kiedrowicz
  0 siblings, 2 replies; 9+ messages in thread
From: Dmitry Potapov @ 2009-04-27 17:46 UTC (permalink / raw)
  To: Git Mailing List

Hi,

I have tried a few version of Git and got "Segmentation fault" when
run:

$ git grep '('

I am not very familiar with grep code and don't have time to dig
into it right now. So, maybe someone else can take a look at it.

Thanks,
Dmitry

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 17:46 git grep '(' = segfault Dmitry Potapov
@ 2009-04-27 18:10 ` Linus Torvalds
  2009-04-27 18:42   ` Erik Faye-Lund
  2009-04-27 18:15 ` Michał Kiedrowicz
  1 sibling, 1 reply; 9+ messages in thread
From: Linus Torvalds @ 2009-04-27 18:10 UTC (permalink / raw)
  To: Dmitry Potapov; +Cc: Git Mailing List



On Mon, 27 Apr 2009, Dmitry Potapov wrote:
> 
> I have tried a few version of Git and got "Segmentation fault" when
> run:
> 
> $ git grep '('
> 
> I am not very familiar with grep code and don't have time to dig
> into it right now. So, maybe someone else can take a look at it.

Good job.

Something like this should fix it.

		Linus

---
 grep.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/grep.c b/grep.c
index f3a27d7..04c777a 100644
--- a/grep.c
+++ b/grep.c
@@ -72,6 +72,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 	struct grep_expr *x;
 
 	p = *list;
+	if (!p)
+		return NULL;
 	switch (p->token) {
 	case GREP_PATTERN: /* atom */
 	case GREP_PATTERN_HEAD:
@@ -84,8 +86,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 	case GREP_OPEN_PAREN:
 		*list = p->next;
 		x = compile_pattern_or(list);
-		if (!x)
-			return NULL;
 		if (!*list || (*list)->token != GREP_CLOSE_PAREN)
 			die("unmatched parenthesis");
 		*list = (*list)->next;
@@ -101,6 +101,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)
 	struct grep_expr *x;
 
 	p = *list;
+	if (!p)
+		return NULL;
 	switch (p->token) {
 	case GREP_NOT:
 		if (!p->next)
@@ -372,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
 	int h = 0;
 	regmatch_t match;
 
+	if (!x)
+		die("Not a valid grep expression");
 	switch (x->node) {
 	case GREP_NODE_ATOM:
 		h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 17:46 git grep '(' = segfault Dmitry Potapov
  2009-04-27 18:10 ` Linus Torvalds
@ 2009-04-27 18:15 ` Michał Kiedrowicz
  1 sibling, 0 replies; 9+ messages in thread
From: Michał Kiedrowicz @ 2009-04-27 18:15 UTC (permalink / raw)
  To: Dmitry Potapov; +Cc: Git Mailing List

Dmitry Potapov <dpotapov@gmail.com> wrote:

> Hi,
> 
> I have tried a few version of Git and got "Segmentation fault" when
> run:
> 
> $ git grep '('
> 
> I am not very familiar with grep code and don't have time to dig
> into it right now. So, maybe someone else can take a look at it.
> 
> Thanks,
> Dmitry
> --

Try this patch, however I'm not sure if it is correct.

---

diff --git a/grep.c b/grep.c
index f3a27d7..5748355 100644
--- a/grep.c
+++ b/grep.c
@@ -84,10 +84,10 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)
 	case GREP_OPEN_PAREN:
 		*list = p->next;
 		x = compile_pattern_or(list);
-		if (!x)
-			return NULL;
 		if (!*list || (*list)->token != GREP_CLOSE_PAREN)
 			die("unmatched parenthesis");
+		if (!x)
+			return NULL;
 		*list = (*list)->next;
 		return x;
 	default:

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 18:10 ` Linus Torvalds
@ 2009-04-27 18:42   ` Erik Faye-Lund
  2009-04-27 18:50     ` Linus Torvalds
  2009-04-27 18:54     ` Matthieu Moy
  0 siblings, 2 replies; 9+ messages in thread
From: Erik Faye-Lund @ 2009-04-27 18:42 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Dmitry Potapov, Git Mailing List

On Mon, Apr 27, 2009 at 8:10 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> Something like this should fix it.
>
>                Linus

(Sorry that you're getting this mail twice, Linus - I forgot to reply all)

This does indeed fix the crash, but I find the resulting operation
quite bizarre. I'm getting a "fatal: unmatched paranthesis", however
"git grep '(('" is happy to simply grep for the double parenthesis.
Now, if I had done "git grep '\('", I'd expect an unmatched
parenthesis-error... Am I misunderstanding something here?

$ git grep '('
fatal: unmatched parenthesis

$ git grep '(('
Documentation/CodingGuidelines: - We use Arithmetic Expansion $(( ... )).
[...]

$ git grep '\('
fatal: command line, '\(': Unmatched ( or \(

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 18:42   ` Erik Faye-Lund
@ 2009-04-27 18:50     ` Linus Torvalds
  2009-04-27 18:53       ` Erik Faye-Lund
  2009-04-27 18:54     ` Matthieu Moy
  1 sibling, 1 reply; 9+ messages in thread
From: Linus Torvalds @ 2009-04-27 18:50 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: Dmitry Potapov, Git Mailing List



On Mon, 27 Apr 2009, Erik Faye-Lund wrote:
> On Mon, Apr 27, 2009 at 8:10 PM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> > Something like this should fix it.
> >
> >                Linus
> 
> (Sorry that you're getting this mail twice, Linus - I forgot to reply all)

Payback time. Now _you'll_ get it twice. Mmmwwhahahahaahaaa!

> $ git grep '('
> fatal: unmatched parenthesis

Try this:

        git grep -e '('

because 'git grep' actually allows multiple patterns, so you can do things 
like

        git grep '(' -e hello --or -e 'hi there' ')' --and -e world

Practical? Maybe.

                Linus

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 18:50     ` Linus Torvalds
@ 2009-04-27 18:53       ` Erik Faye-Lund
  0 siblings, 0 replies; 9+ messages in thread
From: Erik Faye-Lund @ 2009-04-27 18:53 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Dmitry Potapov, Git Mailing List

> Practical? Maybe.

Confusing? Yes. ;)

-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 18:42   ` Erik Faye-Lund
  2009-04-27 18:50     ` Linus Torvalds
@ 2009-04-27 18:54     ` Matthieu Moy
  2009-04-27 19:02       ` Erik Faye-Lund
  1 sibling, 1 reply; 9+ messages in thread
From: Matthieu Moy @ 2009-04-27 18:54 UTC (permalink / raw)
  To: Erik Faye-Lund; +Cc: Linus Torvalds, Dmitry Potapov, Git Mailing List

Erik Faye-Lund <kusmabite@googlemail.com> writes:

> $ git grep '('
> fatal: unmatched parenthesis

try this: git grep -e '('

The idea is that you can do things like

git grep -e foo --and '(' -e bar --or -e boz ')'

to build a boolean expression of expressions.

-- 
Matthieu

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 18:54     ` Matthieu Moy
@ 2009-04-27 19:02       ` Erik Faye-Lund
  2009-04-27 23:18         ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Erik Faye-Lund @ 2009-04-27 19:02 UTC (permalink / raw)
  To: Matthieu Moy; +Cc: Linus Torvalds, Dmitry Potapov, Git Mailing List

Yeah, thanks for explaining. But isn't this functionality kind of
redundant since we have the -E switch?
As far as I can see, "git grep -E "(bar|boz)" should do the same thing
as "git grep -e foo --and '(' -e bar --or -e boz ')'"...

On Mon, Apr 27, 2009 at 8:54 PM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:
> Erik Faye-Lund <kusmabite@googlemail.com> writes:
>
>> $ git grep '('
>> fatal: unmatched parenthesis
>
> try this: git grep -e '('
>
> The idea is that you can do things like
>
> git grep -e foo --and '(' -e bar --or -e boz ')'
>
> to build a boolean expression of expressions.
>
> --
> Matthieu
>



-- 
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: git grep '(' = segfault
  2009-04-27 19:02       ` Erik Faye-Lund
@ 2009-04-27 23:18         ` Junio C Hamano
  0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2009-04-27 23:18 UTC (permalink / raw)
  To: Erik Faye-Lund
  Cc: Matthieu Moy, Linus Torvalds, Dmitry Potapov, Git Mailing List

Erik Faye-Lund <kusmabite@googlemail.com> writes:

> Yeah, thanks for explaining. But isn't this functionality kind of
> redundant since we have the -E switch?
> As far as I can see, "git grep -E "(bar|boz)" should do the same thing
> as "git grep -e foo --and '(' -e bar --or -e boz ')'"...

With -E, --or is not strictly necessary.

With only -E, however, it is cumbersome to express what --and can.  Once
you learn the handiness of --and, naturally you would start wanting to
be able to say --or (especially if you do not even know about -E).

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-04-27 23:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-27 17:46 git grep '(' = segfault Dmitry Potapov
2009-04-27 18:10 ` Linus Torvalds
2009-04-27 18:42   ` Erik Faye-Lund
2009-04-27 18:50     ` Linus Torvalds
2009-04-27 18:53       ` Erik Faye-Lund
2009-04-27 18:54     ` Matthieu Moy
2009-04-27 19:02       ` Erik Faye-Lund
2009-04-27 23:18         ` Junio C Hamano
2009-04-27 18:15 ` Michał Kiedrowicz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).