git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: "brian m. carlson" <sandals@crustytoothpaste.net>,
	git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	"Miriam R." <mirucam@gmail.com>
Subject: Re: [PATCH] run-command: avoid undefined behavior in exists_in_PATH
Date: Tue, 7 Jan 2020 06:08:50 -0500	[thread overview]
Message-ID: <20200107110850.GB1073219@coredump.intra.peff.net> (raw)
In-Reply-To: <20200107020425.GG92456@google.com>

On Mon, Jan 06, 2020 at 06:04:25PM -0800, Jonathan Nieder wrote:

> -- >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

  parent reply	other threads:[~2020-01-07 11:08 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07  1:36 [PATCH] run-command: avoid undefined behavior in exists_in_PATH brian m. carlson
2020-01-07  2:04 ` Jonathan Nieder
2020-01-07  2:16   ` brian m. carlson
2020-01-07  3:40   ` Bryan Turner
2020-01-07  3:41     ` Bryan Turner
2020-01-07 11:08   ` Jeff King [this message]
2020-01-07 11:01 ` Jeff King
2020-01-07 16:58   ` Junio C Hamano
2020-01-08  2:47   ` brian m. carlson
2020-01-08  9:15     ` Miriam R.
2020-01-08 10:28       ` Christian Couder

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=20200107110850.GB1073219@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=mirucam@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /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).