From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Bert Wesarg <bert.wesarg@googlemail.com>
Cc: Git Mailing List <git@vger.kernel.org>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 1/3] add alloc_ref_with_prefix()
Date: Sat, 18 Oct 2008 14:35:47 +0200 [thread overview]
Message-ID: <48F9D823.4000908@lsrfire.ath.cx> (raw)
In-Reply-To: <36ca99e90810180507q2dedf4ck7262239ae91d892f@mail.gmail.com>
Bert Wesarg schrieb:
> On Sat, Oct 18, 2008 at 11:39, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:
>>>> +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?
>> xcalloc() calls calloc(), which zeroes the memory.
> So, you write the memory range twice, just for the last \0?
Well, one could exclude the name part from zeroing, that's true. It's usually
safer to zero a whole block of memory right at allocation time, lest one
forgets, though. I simply kept it they way it was done before.
That said, here's a patch (4/3):
diff --git a/remote.c b/remote.c
index e530a21..184115d 100644
--- a/remote.c
+++ b/remote.c
@@ -753,9 +753,10 @@ 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);
+ struct ref *ref = xmalloc(sizeof(struct ref) + prefixlen + len + 1);
+ memset(ref, sizeof(struct ref));
memcpy(ref->name, prefix, prefixlen);
- memcpy(ref->name + prefixlen, name, len);
+ memcpy(ref->name + prefixlen, name, len + 1);
return ref;
}
next prev parent reply other threads:[~2008-10-18 12:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-18 8:37 [PATCH 1/3] add alloc_ref_with_prefix() René Scharfe
2008-10-18 8:41 ` [PATCH 2/3] use alloc_ref_from_str() everywhere René Scharfe
2008-10-18 8:44 ` [PATCH 3/3] make alloc_ref_from_str() the new alloc_ref() René Scharfe
2008-10-18 9:27 ` [PATCH 1/3] add alloc_ref_with_prefix() Bert Wesarg
2008-10-18 9:39 ` René Scharfe
2008-10-18 12:07 ` Bert Wesarg
2008-10-18 12:35 ` René Scharfe [this message]
2008-10-20 10:34 ` Andreas Ericsson
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=48F9D823.4000908@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=bert.wesarg@googlemail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).