Re: [PATCH v3 02/25] Convert git_snpath() to strbuf_git_path()
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Feb 19, 2014, 23:54 UTC
- Message-ID
- <CACsJy8BJ=OKzGDFwWQF_k_Gp9XeNwf7pe7c6_ebduJXN=xeOxw@mail.gmail.com>
- In-Reply-To
- <xmqqeh2y7jff.fsf@gitster.dls.corp.google.com>
On Thu, Feb 20, 2014 at 6:48 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 25 quoted lines
> Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
>
>> @@ -651,14 +653,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
>> new->name);
>> }
>> }
>> - if (old->path && old->name) {
>> - char log_file[PATH_MAX], ref_file[PATH_MAX];
>> -
>> - git_snpath(log_file, sizeof(log_file), "logs/%s", old->path);
>> - git_snpath(ref_file, sizeof(ref_file), "%s", old->path);
>> - if (!file_exists(ref_file) && file_exists(log_file))
>> - remove_path(log_file);
>> - }
>> + if (old->path && old->name &&
>> + !file_exists(git_path("%s", old->path)) &&
>> + file_exists(git_path("logs/%s", old->path)))
>> + remove_path(git_path("logs/%s", old->path));
>
> Hmph. Is this conversion safe?
>
> This adds three uses of the round-robin path buffer; if a caller of
> this function used two or more path buffers obtained from
> get_pathname() and expected their contents to remain stable across
> the call to this, it will silently break.three round-robin buffers but not all required at the same time, once the first file_exists() returns the first round-robin buffer could be free, and remove_path() calls git_path again, not reusing the result from the second file_exists, so the second buffer is free to go too.
-- Duy