Re: [PATCH 1/3] add alloc_ref_with_prefix()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bert Wesarg wrote:
On Sat, Oct 18, 2008 at 11:39, René Scharfe <rene.scharfe@xxxxxxxxxxxxxx> 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?


calloc() doesn't do the zeroing pass if it gets memory from the kernel,
which guarantees that the memory is already zeroed out. In reality,
calloc() usually saves on both readability and performance over
explicitly nul-terminating strings.

--
Andreas Ericsson                   andreas.ericsson@xxxxxx
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux