From: Junio C Hamano <gitster@pobox.com>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org, orygaw@protonmail.com, rsbecker@nexbridge.com
Subject: Re: [PATCH 2/2] grep.c: tolerate NULL grep_expr in free_pattern_expr()
Date: Mon, 10 Oct 2022 11:11:05 -0700 [thread overview]
Message-ID: <xmqqsfjv35xi.fsf@gitster.g> (raw)
In-Reply-To: <xmqqy1tn36pc.fsf@gitster.g> (Junio C. Hamano's message of "Mon, 10 Oct 2022 10:54:23 -0700")
Junio C Hamano <gitster@pobox.com> writes:
>> static void free_pattern_expr(struct grep_expr *x)
>> {
>> + if (!x)
>> + return;
>> +
>> switch (x->node) {
>> case GREP_NODE_TRUE:
>> case GREP_NODE_ATOM:
>
> This hunk makes sense, but
>
>> @@ -790,8 +793,6 @@ void free_grep_patterns(struct grep_opt *opt)
>> free(p);
>> }
>>
>> - if (!opt->extended)
>> - return;
>> free_pattern_expr(opt->pattern_expression);
>> }
>
> I do not know about this one. We used to avoid freeing, even when
> the .pattern_expression member is set, as long as the .extended bit
> is not set. Now we unconditionally try to free it even when the bit
> says it does not want to. Why?
Ah, grep.c::compile_grep_patterns() has the answer. We only
populate the .pattern_expression member when we are doing a complex
query and leave it empty otherwise. The .pattern_list member is
used instead as a list of OR'ed patterns in grep.c::match_line()
when .extended is not set.
The !opt->extended guard assumes that opt->pattern_expression exists
only when extended is set, which is correct, but forgets that even
when extended is set, pattern_expression is not necessarily non-NULL.
So I think the right thing to do may be to allow free_pattern_expr()
to take and ignore NULL silently? Ah, that is already what you are
doing in the first hunk. Is this second hunk even necessary?
I wonder how calls to grep.c::match_line() with opt->extended true
and opt->pattern_expression NULL, though. It should die() at the
beginning of match_expr_eval(), which probably is OK, but somehow
feels unsatisfactory.
next prev parent reply other threads:[~2022-10-10 18:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 14:33 Git BUG 2.37.3 and 2.38.0 orygaw
2022-10-10 15:40 ` rsbecker
2022-10-10 15:48 ` Taylor Blau
2022-10-10 17:02 ` Junio C Hamano
2022-10-10 16:57 ` [PATCH] log: require --grep for --invert-grep and --all-match, fix segfault Ævar Arnfjörð Bjarmason
2022-10-10 17:34 ` Junio C Hamano
2022-10-10 17:45 ` Junio C Hamano
2022-10-10 18:48 ` Ævar Arnfjörð Bjarmason
2022-10-10 19:00 ` Taylor Blau
2022-10-11 9:48 ` [PATCH v2] grep.c: remove "extended" in favor of "pattern_expression", " Ævar Arnfjörð Bjarmason
2022-10-11 15:46 ` Junio C Hamano
2022-10-10 17:41 ` [PATCH 0/2] grep: tolerate NULL argument to free_grep_expr() Taylor Blau
2022-10-10 17:41 ` [PATCH 1/2] t4202: demonstrate `git log --invert-grep` segfault Taylor Blau
2022-10-10 17:41 ` [PATCH 2/2] grep.c: tolerate NULL grep_expr in free_pattern_expr() Taylor Blau
2022-10-10 17:54 ` Junio C Hamano
2022-10-10 18:10 ` Taylor Blau
2022-10-10 18:11 ` Junio C Hamano [this message]
2022-10-10 18:14 ` Taylor Blau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqsfjv35xi.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=me@ttaylorr.com \
--cc=orygaw@protonmail.com \
--cc=rsbecker@nexbridge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).