From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: "René Scharfe" <l.s.r@web.de>,
"Git Mailing List" <git@vger.kernel.org>,
"Karsten Blees" <karsten.blees@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: Re: [PATCH v2 2/4] use strbuf_getcwd() to get the current working directory without fixed-sized buffers
Date: Mon, 21 Jul 2014 12:02:59 -0700 [thread overview]
Message-ID: <xmqqsiluilgc.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <20140721023312.GC22750@peff.net> (Jeff King's message of "Sun, 20 Jul 2014 22:33:12 -0400")
Jeff King <peff@peff.net> writes:
> On Sun, Jul 20, 2014 at 06:49:54PM +0200, René Scharfe wrote:
>
>> diff --git a/builtin/init-db.c b/builtin/init-db.c
>> index 56f85e2..c4958b6 100644
>> --- a/builtin/init-db.c
>> +++ b/builtin/init-db.c
>> @@ -535,10 +535,10 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
>> usage(init_db_usage[0]);
>> }
>> if (is_bare_repository_cfg == 1) {
>> - static char git_dir[PATH_MAX+1];
>> -
>> - setenv(GIT_DIR_ENVIRONMENT,
>> - getcwd(git_dir, sizeof(git_dir)), argc > 0);
>> + struct strbuf cwd = STRBUF_INIT;
>> + strbuf_getcwd(&cwd);
>> + setenv(GIT_DIR_ENVIRONMENT, cwd.buf, argc > 0);
>> + strbuf_release(&cwd);
>
> Hmm. You are not making anything worse here, as we already do not check
> the return value of getcwd. But what happens if it fails? Looks like we
> currently get a segfault, and the new code will silently set the
> variable to the empty string. Neither is particularly helpful.
>
> Should we be using the xgetcwd helper that you add in the next patch?
>
>> - setenv(GIT_DIR_ENVIRONMENT, getcwd(git_dir, sizeof(git_dir)), 0);
>> + strbuf_getcwd(&cwd);
>> + setenv(GIT_DIR_ENVIRONMENT, cwd.buf, 0);
>> + strbuf_release(&cwd);
>
> Ditto here.
Good eyes.
next prev parent reply other threads:[~2014-07-21 19:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-20 16:46 [PATCH v2 0/4] getcwd without PATH_MAX René Scharfe
2014-07-20 16:49 ` [PATCH v2 1/4] strbuf: add strbuf_getcwd() René Scharfe
2014-07-20 16:49 ` [PATCH v2 2/4] use strbuf_getcwd() to get the current working directory without fixed-sized buffers René Scharfe
2014-07-21 2:33 ` Jeff King
2014-07-21 17:10 ` René Scharfe
2014-07-22 10:43 ` Jeff King
2014-07-21 19:02 ` Junio C Hamano [this message]
2014-07-20 16:50 ` [PATCH v2 3/4] wrapper: add xgetcwd() René Scharfe
2014-07-20 16:51 ` [PATCH v2 4/4] use xgetcwd() get the current directory or die René Scharfe
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=xmqqsiluilgc.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=karsten.blees@gmail.com \
--cc=l.s.r@web.de \
--cc=pclouds@gmail.com \
--cc=peff@peff.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.