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

Re: [PATCH] run-command: avoid undefined behavior in exists_in_PATH

From
Jeff King <peff@peff.net>
Date
Jan 7, 2020, 11:08 UTC
Message-ID
<20200107110850.GB1073219@coredump.intra.peff.net>
In-Reply-To
<20200107020425.GG92456@google.com>
On Mon, Jan 06, 2020 at 06:04:25PM -0800, Jonathan Nieder wrote:
Show 20 quoted lines
> -- >8 --
> Subject: run-command: let caller pass in buffer to locate_in_PATH
> 
> Instead of returning a buffer that the caller is responsible for
> freeing, use a strbuf output parameter to record the path to the
> searched-for program.
> 
> This makes ownership a little easier to reason about, since the owning
> code declares the buffer.  It's a good habit to follow because it
> allows buffer reuse when calling such a function in a loop.
> 
> It also allows the caller exists_in_PATH that does not care about the
> path to the command to be slightly simplified, by allowing a NULL
> output parameter that means that locate_in_PATH should take care of
> allocating and freeing its temporary buffer.
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
>  run-command.c | 51 +++++++++++++++++++++++++++++----------------------
>  1 file changed, 29 insertions(+), 22 deletions(-)

I dunno. Now the rules inside locate_in_PATH() are more complicated, and we have an unusual boolean return from the function.

I admit I don't overly care either way, as there are literally two callers (and not likely to be more). So I'd probably just leave it alone, but I'm not opposed to the patch if people think it's a good idea.

-Peff
Previous: Bryan TurnerNext: Jeff King
Message 6 of 11 in “run-command: avoid undefined behavior in exists_in_PATH”
  1. run-command: avoid undefined behavior in exists_in_PATHbrian m. carlson, Jan 7, 2020
  2. Jonathan NiederJan 7, 2020
  3. brian m. carlsonJan 7, 2020
  4. Bryan TurnerJan 7, 2020
  5. Bryan TurnerJan 7, 2020
  6. Jeff KingJan 7, 2020
  7. Jeff KingJan 7, 2020
  8. Junio C HamanoJan 7, 2020
  9. brian m. carlsonJan 8, 2020
  10. Miriam R.Jan 8, 2020
  11. Christian CouderJan 8, 2020

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.