Re: [PATCH 2/2] grep.c: tolerate NULL grep_expr in free_pattern_expr()
- From
Taylor Blau <me@ttaylorr.com>
- Date
- Oct 10, 2022, 18:14 UTC
- Message-ID
- <Y0Rg9My2EaWl/WCU@nand.local>
- In-Reply-To
- <xmqqsfjv35xi.fsf@gitster.g>
On Mon, Oct 10, 2022 at 11:11:05AM -0700, Junio C Hamano wrote:
Show 5 quoted lines
> Junio C Hamano <gitster@pobox.com> writes: > > 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?
Right. The fix in my patch is to have `free_pattern_expr()` treat its arguments like `free()` does, where NULL is a silent noop.
We could do with or without the second hunk. I dropped it to avoid confusion, but it seems to have had the opposite effect ;-). I'll keep the if-statement there and instead drop the latter hunk.
> 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.
It does, and we can thank Linus for that: c922b01f54 (grep: fix segfault when "git grep '('" is given, 2009-04-27).
Thanks, Taylor