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

Re: [PATCH 1/3] make_absolute_path: return the input path if it points to our buffer

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2011, 20:51 UTC
Message-ID
<7vaagu7pry.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1300291579-25852-2-git-send-email-cmn@elego.de>
Carlos Martín Nieto <cmn@elego.de> writes:
Show 23 quoted lines
> Some codepaths call make_absolute_path with its own return value as
> input. In such a cases, return the path immediately.
>
> This fixes a valgrind-discovered error, whereby we tried to copy a
> string onto itself.
>
> Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
> ---
>  abspath.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/abspath.c b/abspath.c
> index 91ca00f..ff14068 100644
> --- a/abspath.c
> +++ b/abspath.c
> @@ -24,6 +24,10 @@ const char *make_absolute_path(const char *path)
>  	char *last_elem = NULL;
>  	struct stat st;
>  
> +	/* We've already done it */
> +	if (path == buf || path == next_buf)
> +		return path;
> +
I like this, as it is very obvious what we are checking here.  Thanks.
Previous: Carlos Martín NietoNext: Carlos Martín Nieto
Message 3 of 10 in “Rename make_*_path with clearer names”
  1. 0/3 Rename make_*_path with clearer namesCarlos Martín Nieto, Mar 16, 2011
  2. 1/3 make_absolute_path: return the input path if it points to our bufferCarlos Martín Nieto, Mar 16, 2011
  3. Junio C HamanoMar 16, 2011
  4. 2/3 Name make_*_path functions more accuratelyCarlos Martín Nieto, Mar 16, 2011
  5. Brian GernhardtMar 16, 2011
  6. Carlos Martín NietoMar 16, 2011
  7. 3/3 Use the new {real,absolute}_path function namesCarlos Martín Nieto, Mar 16, 2011
  8. Erik Faye-LundMar 16, 2011
  9. Carlos Martín NietoMar 16, 2011
  10. 3/3 Name make_*_path functions more accuratelyCarlos Martín Nieto, Mar 16, 2011

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.