Re: [PATCH 1/3] add alloc_ref_with_prefix()
- From
Bert Wesarg <bert.wesarg@googlemail.com>
- Date
- Oct 18, 2008, 09:27 UTC
- Message-ID
- <36ca99e90810180227u367783f6vc3b7af0176f6df06@mail.gmail.com>
- In-Reply-To
- <48F9A054.4010703@lsrfire.ath.cx>
On Sat, Oct 18, 2008 at 10:37, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:
Show 28 quoted lines
> In three cases in remote.c, a "raw" ref is allocated using alloc_ref()
> and then its is constructed using sprintf(). Clean it up by adding a
> helper function, alloc_ref_with_prefix(), which creates a composite
> name. Use it in alloc_ref_from_str(), too, as it simplifies the code.
>
> Open code alloc_ref() in alloc_ref_with_prefix(), as the former is
> going to be removed in the patch after the next.
>
> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
> ---
> remote.c | 32 ++++++++++++++++----------------
> 1 files changed, 16 insertions(+), 16 deletions(-)
>
> diff --git a/remote.c b/remote.c
> index 8a04066..98cbcf9 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -749,6 +749,16 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
> return -1;
> }
>
> +static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen,
> + const char *name)
> +{
> + size_t len = strlen(name);
> + struct ref *ref = xcalloc(1, sizeof(struct ref) + prefixlen + len + 1);
> + memcpy(ref->name, prefix, prefixlen);
> + memcpy(ref->name + prefixlen, name, len);Where does you \0-terminate the string?
Regards Bert