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

Re: [PATCH] abspath: increase array size of cwd variable to PATH_MAX

From
Wwanghui <hui.wang@windriver.com>
Date
Sep 22, 2011, 08:54 UTC
Message-ID
<4E7AF7B8.2080208@windriver.com>
In-Reply-To
<7vty851wg9.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 12 quoted lines
> Ramsay Jones <ramsay@ramsay1.demon.co.uk> writes:
>
>   
>> Hmm, the subject line says "... increase array size ...", but that is not
>> necessarily what this patch is doing! :-D
>>     
>
> True; will revert it out of 'next'.
>
> Thanks for noticing.
>
>   
Hi Junio and Ramsay,
In fact, i found lots of similar usage in the git source code. E.G.

in the dir.c, int is_inside_dir(const char *dir) { char cwd[PATH_MAX]; if (!dir) return 0; if (!getcwd(cwd, sizeof(cwd))) die_errno("can't find the current directory"); return dir_inside_of(cwd, dir) >= 0; }

Since this implementation is not cross-OS safe, Could we use below solution?

step1, add a new function xgetcwd() to wrapper getcwd() like this: char *xgetcwd(void) { size_t size = 100;

while (1) { char *buffer = (char *) xmalloc (size); if (getcwd (buffer, size) == buffer) return buffer; free (buffer); if (errno != ERANGE) return 0; size *= 2; } }

step2, use xgetcwd to replace all getcwd occurrence in the git source code.
This will add a little bit overhead to the git, but it is cross-OS safe.
Previous: Junio C HamanoNext: wanghui
Message 5 of 6 in “abspath: increase array size of cwd variable to PATH_MAX”
  1. abspath: increase array size of cwd variable to PATH_MAXWang Hui, Sep 19, 2011
  2. Junio C HamanoSep 19, 2011
  3. Ramsay JonesSep 20, 2011
  4. Junio C HamanoSep 21, 2011
  5. wanghuiSep 22, 2011
  6. wanghuiSep 22, 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.