git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* xmemdup patches
@ 2007-09-17 16:11 Pierre Habouzit
  2007-09-15 21:53 ` [PATCH 1/2] Add xmemdup that duplicates a block of memory, and NUL terminates it Pierre Habouzit
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Pierre Habouzit @ 2007-09-17 16:11 UTC (permalink / raw)
  To: Git ML

[-- Attachment #1: Type: text/plain, Size: 997 bytes --]

  I noticed a lot of places in git's code use code like:

  char *res;

  ...

  res = xmalloc(len + 1);
  memcpy(res, src, len);
  res[len] = '\0';
  return res;

  I've added a "xmemdup" function that duplicates a portion of memory,
also adding an extra NUL after the end of the buffer. There was a
xstrndup already, doing almost the same, except that it worked like
strndup, meaning that it duplicates the memory areay up to len or the
first embeded NUL. The extra scan costs, and is often not necessary (as
we want to extract a token from a buffer we just validated e.g.).

  There were 41 of those places.


  I'm not a huge fan of "xmemdup" as I would not have supposed that a
function called like that would add the extra NUL, so I'm 100% okay with
someone coming up with any better name.
-- 
·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-09-19  8:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-17 16:11 xmemdup patches Pierre Habouzit
2007-09-15 21:53 ` [PATCH 1/2] Add xmemdup that duplicates a block of memory, and NUL terminates it Pierre Habouzit
2007-09-15 22:32 ` [PATCH 2/2] Use xmemdup in many places Pierre Habouzit
2007-09-19  8:08   ` Junio C Hamano
2007-09-19  8:26     ` Pierre Habouzit
2007-09-17 16:14 ` xmemdup patches Pierre Habouzit
2007-09-17 16:39 ` Johannes Schindelin
2007-09-17 17:43   ` Pierre Habouzit

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).