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

Re: [PATCH] abspath.c: use PATH_MAX in real_path_internal()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 17, 2014, 18:03 UTC
Message-ID
<xmqqoawnq2vv.fsf@gitster.dls.corp.google.com>
In-Reply-To
<1405601143-31354-1-git-send-email-pclouds@gmail.com>
Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:
Show 7 quoted lines
> This array 'cwd' is used to store the result from getcwd() and chdir()
> back. PATH_MAX is the right constant for the job. On systems with
> longer PATH_MAX (eg. 4096 on Linux), hard coding 1024 fails stuff,
> e.g. "git init". Make it static too to reduce stack usage.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---

Thanks. It seems that this 1024 has been with us since the beginning of this piece of code. I briefly wondered if there are strange platform that will have PATH_MAX shorter than 1024 that will be hurt by this change, but the result in cwd[] is used to grow the final result bufs[] that is sized based on PATH_MAX anyway, so it will not be an issue (besides, the absurdly short one seems to be a different macro, MAX_PATH, on Windows).

Will queue.
Show 25 quoted lines
>  abspath.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/abspath.c b/abspath.c
> index ca33558..c0c868f 100644
> --- a/abspath.c
> +++ b/abspath.c
> @@ -41,7 +41,7 @@ static const char *real_path_internal(const char *path, int die_on_error)
>  	 * here so that we can chdir() back to it at the end of the
>  	 * function:
>  	 */
> -	char cwd[1024] = "";
> +	static char cwd[PATH_MAX];
>  
>  	int buf_index = 1;
>  
> @@ -49,6 +49,8 @@ static const char *real_path_internal(const char *path, int die_on_error)
>  	char *last_elem = NULL;
>  	struct stat st;
>  
> +	*cwd = '\0';
> +
>  	/* We've already done it */
>  	if (path == buf || path == next_buf)
>  		return path;
Previous: René ScharfeNext: Karsten Blees
Message 14 of 17 in “abspath.c: use PATH_MAX in real_path_internal()”
  1. abspath.c: use PATH_MAX in real_path_internal()Nguyễn Thái Ngọc Duy, Jul 17, 2014
  2. René ScharfeJul 17, 2014
  3. Junio C HamanoJul 17, 2014
  4. Karsten BleesJul 17, 2014
  5. Duy NguyenJul 18, 2014
  6. René ScharfeJul 18, 2014
  7. Duy NguyenJul 19, 2014
  8. Karsten BleesJul 20, 2014
  9. René ScharfeJul 20, 2014
  10. Jeff KingJul 21, 2014
  11. René ScharfeJul 18, 2014
  12. Karsten BleesJul 19, 2014
  13. René ScharfeJul 20, 2014
  14. Junio C HamanoJul 17, 2014
  15. Karsten BleesJul 17, 2014
  16. Karsten BleesJul 17, 2014
  17. Junio C HamanoJul 18, 2014

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.