git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Blau <me@ttaylorr.com>,
	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 14:10:40 -0400	[thread overview]
Message-ID: <Y0RgIGpxXXilh7YM@nand.local> (raw)
In-Reply-To: <xmqqy1tn36pc.fsf@gitster.g>

On Mon, Oct 10, 2022 at 10:54:23AM -0700, Junio C Hamano wrote:
> Taylor Blau <me@ttaylorr.com> writes:
> > @@ -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?

It's not "does not want to" be freed. As best I can tell, we conflate
`opt->extended` with "there is something in `opt->pattern_expression`".
So checking whether or not `opt->extended` is non-zero isn't "keep this
around because I'm going to use it later", but instead "there is
nothing to free, don't bother calling `free_pattern_expr()`".

A more direct way of saying the latter would have been to replace the
if-statement with `if (opt->pattern_expression)`.

I hinted at this in the commit message, but I will make it more direct
to avoid future readers' confusion.

> > diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> > index e3ec5f5661..44f7ef0ea2 100755
> > --- a/t/t4202-log.sh
> > +++ b/t/t4202-log.sh
> > @@ -297,7 +297,7 @@ test_expect_success 'log --invert-grep --grep -i' '
> >  	fi
> >  '
> >
> > -test_expect_failure 'log --invert-grep (no --grep)' '
> > +test_expect_success 'log --invert-grep (no --grep)' '
> >  	git log --pretty="tformat:%s" >expect &&
> >  	git log --invert-grep --pretty="tformat:%s" >actual &&
> >  	test_cmp expect actual
>
> Especially for something this small, doing the "failing test first
> and then fix with flipping the test to success" is very much
> unwelcome.  For whoever gets curious (me included when accepting
> posted patch), it is easy to revert only the part of the commit
> outside t/ tentatively to see how the original code breaks.  Keeping
> the fix and protection of the fix together will avoid mistakes.  In
> this case, the whole test fits inside the post context of the patch,
> but in general, this "flip failure to success" will hide the body of
> the test that changes behaviour while reviewing the patch text,
> which is another downside.

Good to know. I had considered it good practice, even for a small fix,
as a way to show your work and prove that you had a legitimately broken
test case demonstrating the bug. But if it creates an extra hassle, I
don't mind squashing it down.

I can send a squashed version of these two patches, but let's see if
there are any other comments, first.

Thanks,
Taylor

  reply	other threads:[~2022-10-10 18:10 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 [this message]
2022-10-10 18:11       ` Junio C Hamano
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=Y0RgIGpxXXilh7YM@nand.local \
    --to=me@ttaylorr.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).