git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/6] diff: clear emitted_symbols flag after use

From
Jeff King <peff@peff.net>
Date
Jan 24, 2019, 21:17 UTC
Message-ID
<20190124211715.GB16114@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kZR--VN2BiG=usyy=J=u59Up3XYpK4c9pJYQkX1Gby06Q@mail.gmail.com>
On Thu, Jan 24, 2019 at 12:36:38PM -0800, Stefan Beller wrote:
Show 24 quoted lines
> >  - 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.

Show 10 quoted lines
> >  - 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
Previous: Stefan BellerNext: Jeff King
Message 9 of 19 in “some diff --cc --stat fixes”
  1. 0/6 some diff --cc --stat fixesJeff King, Jan 24, 2019
  2. 1/6 t4006: resurrect commented-out testsJeff King, Jan 24, 2019
  3. Stefan BellerJan 24, 2019
  4. 2/6 diff: clear emitted_symbols flag after useJeff King, Jan 24, 2019
  5. Stefan BellerJan 24, 2019
  6. Jeff KingJan 24, 2019
  7. Junio C HamanoJan 24, 2019
  8. Stefan BellerJan 24, 2019
  9. Jeff KingJan 24, 2019
  10. Jeff KingJan 24, 2019
  11. 3/6 combine-diff: factor out stat-format maskJeff King, Jan 24, 2019
  12. 4/6 combine-diff: treat --shortstat like --statJeff King, Jan 24, 2019
  13. David TurnerJan 24, 2019
  14. Stefan BellerJan 24, 2019
  15. 5/6 combine-diff: treat --summary like --statJeff King, Jan 24, 2019
  16. Stefan BellerJan 24, 2019
  17. Jeff KingJan 24, 2019
  18. 6/6 combine-diff: treat --dirstat like --statJeff King, Jan 24, 2019
  19. Stefan BellerJan 24, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.