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

Re: Probable bug in file run-command.c function clear_child_for_cleanup

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Sep 10, 2012, 13:58 UTC
Message-ID
<CABPQNSaufY9vUAFp9VL2i=6bNmO5_2+anzX6+omfq+UgP03kXg@mail.gmail.com>
In-Reply-To
<20120910134406.GA7496@sigill.intra.peff.net>
On Mon, Sep 10, 2012 at 3:44 PM, Jeff King <peff@peff.net> wrote:
Show 20 quoted lines
> On Sun, Sep 09, 2012 at 03:44:54PM +0100, David Gould wrote:
>> You want something like:
>>
>> for (... {
>>       if (... {
>>               ...
>>       }
>>       last = &p->next;
>> }
>>
>> or (probably clearer, but I haven't read your coding style guide, if
>> there is one, and some people don't like this approach)
>
> Yes, that's the correct fix. Care to submit a patch?
>
>> for (p = children_to_clean; p; last = &p->next, p = p->next) {
>>       ...
>
> That is OK, too, but I think I prefer the first one.
>
I feel like bikeshedding a bit today!
I tend to either prefer either the latter or something like this:
while (p) {
	...
	last = p;
	p = p->next;
}

because those approaches put all the iteration logic in the same place. The in-body traversal approach is a bit more explicit about the traversal details.

And to conclude my bikeshedding for the day: Shouldn't "last" ideally be called something like "prev" instead? It's the previously visited element, not the last element in the list.

Previous: Jeff KingNext: Jeff King
Message 3 of 8 in “Probable bug in file run-command.c function clear_child_for_cleanup”
  1. David GouldSep 9, 2012
  2. Jeff KingSep 10, 2012
  3. Erik Faye-LundSep 10, 2012
  4. Jeff KingSep 10, 2012
  5. Junio C HamanoSep 10, 2012
  6. Jeff KingSep 10, 2012
  7. Junio C HamanoSep 10, 2012
  8. David GouldSep 11, 2012

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.