git/list[1] front-page[2] threads[3] people[4] search[5] about
 

xmemdup patches

From
Pierre Habouzit <madcoder@debian.org>
Date
Sep 17, 2007, 16:11 UTC
Message-ID
<20070917161113.GB460@artemis.corp>
  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
Next: Pierre Habouzit
Message 1 of 8 in “xmemdup patches”
  1. Pierre HabouzitSep 17, 2007
  2. 1/2 Add xmemdup that duplicates a block of memory, and NUL terminates it.Pierre Habouzit, Sep 15, 2007
  3. 2/2 Use xmemdup in many places.Pierre Habouzit, Sep 15, 2007
  4. Junio C HamanoSep 19, 2007
  5. Pierre HabouzitSep 19, 2007
  6. Pierre HabouzitSep 17, 2007
  7. Johannes SchindelinSep 17, 2007
  8. Pierre HabouzitSep 17, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.