All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: git@vger.kernel.org,
	"Johannes Schindelin" <johannes.schindelin@gmx.de>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [BUG?] git range-diff -Ix @{1}... segfaults
Date: Tue, 07 Sep 2021 13:05:12 -0700	[thread overview]
Message-ID: <xmqq7dfsb18n.fsf@gitster.g> (raw)
In-Reply-To: <7ac58fa9-f0f3-53bc-e51b-de9cd4efdb29@web.de> ("René Scharfe"'s message of "Sat, 4 Sep 2021 09:50:58 +0200")

René Scharfe <l.s.r@web.de> writes:

> range-diff.c::output() calls diff.c::diff_flush() in a loop with the
> same struct diff_options (via range-diff.c::patch_diff()).

Woooo, that's, eh, unexpected.

> So the second iteration of that loop tries to use the already freed
> ignore regexes.  Here's a patch for that:

Thanks.

>
> --- >8 ---
> Subject: [PATCH] range-diff: avoid segfault with -I
>
> output() reuses the same struct diff_options for multiple calls of
> diff_flush().  Set the option no_free to instruct it to keep the
> ignore regexes between calls and release them explicitly at the end.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> Test missing because I couldn't see any effect of -I on range-diff.

I wanted to omit my sign-off when comparing a previous series and
the new series (iow, I expected -I"^Signed-off-by: me" to apply to
the outer diff, not the inner "generation of patches to be compared").


>  range-diff.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/range-diff.c b/range-diff.c
> index e731525e66..cac89a2f4f 100644
> --- a/range-diff.c
> +++ b/range-diff.c
> @@ -482,6 +482,7 @@ static void output(struct string_list *a, struct string_list *b,
>  	else
>  		diff_setup(&opts);
>
> +	opts.no_free = 1;
>  	if (!opts.output_format)
>  		opts.output_format = DIFF_FORMAT_PATCH;
>  	opts.flags.suppress_diff_headers = 1;
> @@ -542,6 +543,8 @@ static void output(struct string_list *a, struct string_list *b,
>  	strbuf_release(&buf);
>  	strbuf_release(&dashes);
>  	strbuf_release(&indent);
> +	opts.no_free = 0;
> +	diff_free(&opts);
>  }
>
>  int show_range_diff(const char *range1, const char *range2,
> --
> 2.33.0

      reply	other threads:[~2021-09-07 20:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-03 18:49 [BUG?] git range-diff -Ix @{1}... segfaults Junio C Hamano
2021-09-04  7:50 ` René Scharfe
2021-09-07 20:05   ` Junio C Hamano [this message]

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=xmqq7dfsb18n.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=l.s.r@web.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.