{"thread":{"id":"19089","subject":"git grep '(' = segfault","startedAt":"2009-04-27T17:46:04Z","lastAt":"2009-04-27T23:18:12Z","messageCount":9,"participants":["Dmitry Potapov","Linus Torvalds","Michał Kiedrowicz","Erik Faye-Lund","Matthieu Moy","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"112441","messageId":"37fcd2780904271046r7740ed42t3c9438e7aa93374@mail.gmail.com","threadId":"19089","inReplyTo":null,"subject":"git grep '(' = segfault","fromName":"Dmitry Potapov","fromEmail":"dpotapov@gmail.com","sentAt":"2009-04-27T17:46:04Z","receivedAt":"2009-04-27T17:46:04Z","isPatch":false,"sender":{"key":"dpotapov@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6568595?v=4"},"body":"Hi,\n\nI have tried a few version of Git and got \"Segmentation fault\" when\nrun:\n\n$ git grep '('\n\nI am not very familiar with grep code and don't have time to dig\ninto it right now. So, maybe someone else can take a look at it.\n\nThanks,\nDmitry\n"},{"id":"112444","messageId":"alpine.LFD.2.00.0904271059060.22156@localhost.localdomain","threadId":"19089","inReplyTo":"37fcd2780904271046r7740ed42t3c9438e7aa93374@mail.gmail.com","subject":"Re: git grep '(' = segfault","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-04-27T18:10:24Z","receivedAt":"2009-04-27T18:10:24Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 27 Apr 2009, Dmitry Potapov wrote:\n> \n> I have tried a few version of Git and got \"Segmentation fault\" when\n> run:\n> \n> $ git grep '('\n> \n> I am not very familiar with grep code and don't have time to dig\n> into it right now. So, maybe someone else can take a look at it.\n\nGood job.\n\nSomething like this should fix it.\n\n\t\tLinus\n\n---\n grep.c |    8 ++++++--\n 1 files changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/grep.c b/grep.c\nindex f3a27d7..04c777a 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -72,6 +72,8 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)\n \tstruct grep_expr *x;\n \n \tp = *list;\n+\tif (!p)\n+\t\treturn NULL;\n \tswitch (p->token) {\n \tcase GREP_PATTERN: /* atom */\n \tcase GREP_PATTERN_HEAD:\n@@ -84,8 +86,6 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)\n \tcase GREP_OPEN_PAREN:\n \t\t*list = p->next;\n \t\tx = compile_pattern_or(list);\n-\t\tif (!x)\n-\t\t\treturn NULL;\n \t\tif (!*list || (*list)->token != GREP_CLOSE_PAREN)\n \t\t\tdie(\"unmatched parenthesis\");\n \t\t*list = (*list)->next;\n@@ -101,6 +101,8 @@ static struct grep_expr *compile_pattern_not(struct grep_pat **list)\n \tstruct grep_expr *x;\n \n \tp = *list;\n+\tif (!p)\n+\t\treturn NULL;\n \tswitch (p->token) {\n \tcase GREP_NOT:\n \t\tif (!p->next)\n@@ -372,6 +374,8 @@ static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,\n \tint h = 0;\n \tregmatch_t match;\n \n+\tif (!x)\n+\t\tdie(\"Not a valid grep expression\");\n \tswitch (x->node) {\n \tcase GREP_NODE_ATOM:\n \t\th = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);\n"},{"id":"112445","messageId":"20090427201513.5d598e3c@gmail.com","threadId":"19089","inReplyTo":"37fcd2780904271046r7740ed42t3c9438e7aa93374@mail.gmail.com","subject":"Re: git grep '(' = segfault","fromName":"Michał Kiedrowicz","fromEmail":"michal.kiedrowicz@gmail.com","sentAt":"2009-04-27T18:15:13Z","receivedAt":"2009-04-27T18:15:13Z","isPatch":false,"sender":{"key":"michal.kiedrowicz@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14072847?v=4"},"body":"Dmitry Potapov <dpotapov@gmail.com> wrote:\n\n> Hi,\n> \n> I have tried a few version of Git and got \"Segmentation fault\" when\n> run:\n> \n> $ git grep '('\n> \n> I am not very familiar with grep code and don't have time to dig\n> into it right now. So, maybe someone else can take a look at it.\n> \n> Thanks,\n> Dmitry\n> --\n\nTry this patch, however I'm not sure if it is correct.\n\n---\n\ndiff --git a/grep.c b/grep.c\nindex f3a27d7..5748355 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -84,10 +84,10 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list)\n \tcase GREP_OPEN_PAREN:\n \t\t*list = p->next;\n \t\tx = compile_pattern_or(list);\n-\t\tif (!x)\n-\t\t\treturn NULL;\n \t\tif (!*list || (*list)->token != GREP_CLOSE_PAREN)\n \t\t\tdie(\"unmatched parenthesis\");\n+\t\tif (!x)\n+\t\t\treturn NULL;\n \t\t*list = (*list)->next;\n \t\treturn x;\n \tdefault:\n"},{"id":"112450","messageId":"40aa078e0904271142u71d7ba97w9df80667c0d9b955@mail.gmail.com","threadId":"19089","inReplyTo":"alpine.LFD.2.00.0904271059060.22156@localhost.localdomain","subject":"Re: git grep '(' = segfault","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-04-27T18:42:37Z","receivedAt":"2009-04-27T18:42:37Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Mon, Apr 27, 2009 at 8:10 PM, Linus Torvalds\n<torvalds@linux-foundation.org> wrote:\n> Something like this should fix it.\n>\n>                Linus\n\n(Sorry that you're getting this mail twice, Linus - I forgot to reply all)\n\nThis does indeed fix the crash, but I find the resulting operation\nquite bizarre. I'm getting a \"fatal: unmatched paranthesis\", however\n\"git grep '(('\" is happy to simply grep for the double parenthesis.\nNow, if I had done \"git grep '\\('\", I'd expect an unmatched\nparenthesis-error... Am I misunderstanding something here?\n\n$ git grep '('\nfatal: unmatched parenthesis\n\n$ git grep '(('\nDocumentation/CodingGuidelines: - We use Arithmetic Expansion $(( ... )).\n[...]\n\n$ git grep '\\('\nfatal: command line, '\\(': Unmatched ( or \\(\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"112451","messageId":"alpine.LFD.2.00.0904271149480.22156@localhost.localdomain","threadId":"19089","inReplyTo":"40aa078e0904271142u71d7ba97w9df80667c0d9b955@mail.gmail.com","subject":"Re: git grep '(' = segfault","fromName":"Linus Torvalds","fromEmail":"torvalds@linux-foundation.org","sentAt":"2009-04-27T18:50:38Z","receivedAt":"2009-04-27T18:50:38Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Mon, 27 Apr 2009, Erik Faye-Lund wrote:\n> On Mon, Apr 27, 2009 at 8:10 PM, Linus Torvalds\n> <torvalds@linux-foundation.org> wrote:\n> > Something like this should fix it.\n> >\n> >                Linus\n> \n> (Sorry that you're getting this mail twice, Linus - I forgot to reply all)\n\nPayback time. Now _you'll_ get it twice. Mmmwwhahahahaahaaa!\n\n> $ git grep '('\n> fatal: unmatched parenthesis\n\nTry this:\n\n        git grep -e '('\n\nbecause 'git grep' actually allows multiple patterns, so you can do things \nlike\n\n        git grep '(' -e hello --or -e 'hi there' ')' --and -e world\n\nPractical? Maybe.\n\n                Linus\n"},{"id":"112452","messageId":"40aa078e0904271153s48fccf1dj4b1bff62abbaf049@mail.gmail.com","threadId":"19089","inReplyTo":"alpine.LFD.2.00.0904271149480.22156@localhost.localdomain","subject":"Re: git grep '(' = segfault","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-04-27T18:53:35Z","receivedAt":"2009-04-27T18:53:35Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"> Practical? Maybe.\n\nConfusing? Yes. ;)\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"112453","messageId":"vpqfxfund0m.fsf@bauges.imag.fr","threadId":"19089","inReplyTo":"40aa078e0904271142u71d7ba97w9df80667c0d9b955@mail.gmail.com","subject":"Re: git grep '(' = segfault","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2009-04-27T18:54:17Z","receivedAt":"2009-04-27T18:54:17Z","isPatch":false,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Erik Faye-Lund <kusmabite@googlemail.com> writes:\n\n> $ git grep '('\n> fatal: unmatched parenthesis\n\ntry this: git grep -e '('\n\nThe idea is that you can do things like\n\ngit grep -e foo --and '(' -e bar --or -e boz ')'\n\nto build a boolean expression of expressions.\n\n-- \nMatthieu\n"},{"id":"112454","messageId":"40aa078e0904271202ye89ebf2wf417c623d8fe5689@mail.gmail.com","threadId":"19089","inReplyTo":"vpqfxfund0m.fsf@bauges.imag.fr","subject":"Re: git grep '(' = segfault","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-04-27T19:02:31Z","receivedAt":"2009-04-27T19:02:31Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Yeah, thanks for explaining. But isn't this functionality kind of\nredundant since we have the -E switch?\nAs far as I can see, \"git grep -E \"(bar|boz)\" should do the same thing\nas \"git grep -e foo --and '(' -e bar --or -e boz ')'\"...\n\nOn Mon, Apr 27, 2009 at 8:54 PM, Matthieu Moy <Matthieu.Moy@imag.fr> wrote:\n> Erik Faye-Lund <kusmabite@googlemail.com> writes:\n>\n>> $ git grep '('\n>> fatal: unmatched parenthesis\n>\n> try this: git grep -e '('\n>\n> The idea is that you can do things like\n>\n> git grep -e foo --and '(' -e bar --or -e boz ')'\n>\n> to build a boolean expression of expressions.\n>\n> --\n> Matthieu\n>\n\n\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"112482","messageId":"7vd4axwurv.fsf@gitster.siamese.dyndns.org","threadId":"19089","inReplyTo":"40aa078e0904271202ye89ebf2wf417c623d8fe5689@mail.gmail.com","subject":"Re: git grep '(' = segfault","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-27T23:18:12Z","receivedAt":"2009-04-27T23:18:12Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Erik Faye-Lund <kusmabite@googlemail.com> writes:\n\n> Yeah, thanks for explaining. But isn't this functionality kind of\n> redundant since we have the -E switch?\n> As far as I can see, \"git grep -E \"(bar|boz)\" should do the same thing\n> as \"git grep -e foo --and '(' -e bar --or -e boz ')'\"...\n\nWith -E, --or is not strictly necessary.\n\nWith only -E, however, it is cumbersome to express what --and can.  Once\nyou learn the handiness of --and, naturally you would start wanting to\nbe able to say --or (especially if you do not even know about -E).\n"}]}