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

Re: [PATCH] Handle the errors from chdir in set_work_tree

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2007, 22:18 UTC
Message-ID
<7v4pjhtwag.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20070802221518.GC2829@steel.home>
Alex Riesen <raa.lkml@gmail.com> writes:
Show 9 quoted lines
> Junio C Hamano, Thu, Aug 02, 2007 23:58:41 +0200:
>> "Alex Riesen" <raa.lkml@gmail.com> writes:
>> > +		if (chdir(dir))
>> > +			rel = NULL;
> ...
>> 
>> Shouldn't it die() instead, though?
>
> Dunno. Don't like dying.

I do not understand your reasoning. Why is it better to use mysteriously truncated path, which may result in doing something the user did not ask you to, rather than saying "No, my temporary buffer is not equipped to handle such an insanely long pathname"?

Show 8 quoted lines
>> Consolidating two of your patches, would this be Ok?
>
> Yes, but you may consider replacing strncpy with strlcpy:
>
>> +		memcpy(dir_buffer, dir, len - suffix_len);
>> +		dir_buffer[len - suffix_len] = '\0';
>
> strlcpy(dir_buffer, dir, len - suffix_len + 1);

Does that buy us that much? Before going to that codepath, we have made sure the result fits, haven't we?

Previous: Alex Riesen
Message 6 of 6 in “Handle the errors from chdir in set_work_tree”
  1. Handle the errors from chdir in set_work_treeAlex Riesen, Aug 2, 2007
  2. Johannes SchindelinAug 2, 2007
  3. Junio C HamanoAug 2, 2007
  4. Johannes SchindelinAug 2, 2007
  5. Alex RiesenAug 2, 2007
  6. Junio C HamanoAug 2, 2007

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.