git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Stefan Beller <sbeller@google.com>
Cc: Junio C Hamano <gitster@pobox.com>, git <git@vger.kernel.org>,
	David Turner <novalis@novalis.org>
Subject: Re: [PATCH 2/6] diff: clear emitted_symbols flag after use
Date: Thu, 24 Jan 2019 16:17:15 -0500	[thread overview]
Message-ID: <20190124211715.GB16114@sigill.intra.peff.net> (raw)
In-Reply-To: <CAGZ79kZR--VN2BiG=usyy=J=u59Up3XYpK4c9pJYQkX1Gby06Q@mail.gmail.com>

On Thu, Jan 24, 2019 at 12:36:38PM -0800, Stefan Beller wrote:

> >  - In an if() block we enter when o->emitted_symbols is set, there
> >    is a check to see if o->color_moved is set.  This makes sense
> >    only if we are trying to be prepared to handle a case where we
> >    are not the one that assigned a non-NULL to o->emitted_symbols
> >    due to o->color_moved.  So it certainly is possible that
> >    o->emitted_symbols is set before we enter this function.
> 
> Ah I see where you are coming from, as the code was written
> I imagined:
> 
>     if (o->color_moved)
>         o->emitted_symbols = &esm;
>     if (o->distim_gostaks)
>         o->emitted_symbols = &esm;
> 
>     if (o->emitted_symbols) {
>          if (o->color_moved)
>             handle_color_moved(o);
>         if (o->distim_gostaks)
>             handle_distimming(o);
> 
>         ... flush symbols...
>         ... free &cleanup ...
>     }

Yeah, FWIW this is what I took to be the reason for the code being laid
out as it is.

> >  - But then, it means that o->emitted_symbols we may have had
> >    non-NULL when the function is called may be overwritten if
> >    o->color_moved is set.
> 
> I see. So either we'd want to have
> 
>     if (o->emitted_symbols)
>         BUG("should not be already set");
> 
> or as Peff points out, make it non-static.

Even if it's non-static, you'd still want to ensure that it's not set
coming into the function (because somebody like diff-words might have
left it set, confusing us). So I think that BUG() may be worth having
either way.

-Peff

  reply	other threads:[~2019-01-24 21:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-24 12:26 [PATCH 0/6] some diff --cc --stat fixes Jeff King
2019-01-24 12:27 ` [PATCH 1/6] t4006: resurrect commented-out tests Jeff King
2019-01-24 18:18   ` Stefan Beller
2019-01-24 12:32 ` [PATCH 2/6] diff: clear emitted_symbols flag after use Jeff King
2019-01-24 18:55   ` Stefan Beller
2019-01-24 19:11     ` Jeff King
2019-01-24 20:18   ` Junio C Hamano
2019-01-24 20:36     ` Stefan Beller
2019-01-24 21:17       ` Jeff King [this message]
2019-01-24 21:15     ` Jeff King
2019-01-24 12:33 ` [PATCH 3/6] combine-diff: factor out stat-format mask Jeff King
2019-01-24 12:34 ` [PATCH 4/6] combine-diff: treat --shortstat like --stat Jeff King
2019-01-24 18:58   ` David Turner
2019-01-24 19:02   ` Stefan Beller
2019-01-24 12:35 ` [PATCH 5/6] combine-diff: treat --summary " Jeff King
2019-01-24 19:14   ` Stefan Beller
2019-01-24 19:23     ` Jeff King
2019-01-24 12:36 ` [PATCH 6/6] combine-diff: treat --dirstat " Jeff King
2019-01-24 19:21 ` [PATCH 0/6] some diff --cc --stat fixes Stefan Beller

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=20190124211715.GB16114@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=novalis@novalis.org \
    --cc=sbeller@google.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).