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

[PATCH] alloc_ref(): allow for trailing NUL

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Sep 28, 2007, 02:57 UTC
Message-ID
<Pine.LNX.4.64.0709280356550.28395@racer.site>

The parameter name "namelen" suggests that you pass the equivalent of strlen() to the function alloc_ref(). However, this function did not allocate enough space to put a NUL after the name.

Since struct ref does not have any member to describe the length of the string, this just does not make sense.

So make space for the NUL.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 remote.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/remote.c b/remote.c
index e7d735b..7531c92 100644
--- a/remote.c
+++ b/remote.c
@@ -453,7 +453,7 @@ int remote_find_tracking(struct remote *remote, struct refspec *refspec)
 
 struct ref *alloc_ref(unsigned namelen)
 {
-	struct ref *ret = xmalloc(sizeof(struct ref) + namelen);
+	struct ref *ret = xmalloc(sizeof(struct ref) + namelen + 1);
 	memset(ret, 0, sizeof(struct ref) + namelen);
 	return ret;
 }
-- 
1.5.3.2.1102.g9487
Next: Daniel Barkalow
Message 1 of 9 in “alloc_ref(): allow for trailing NUL”
  1. alloc_ref(): allow for trailing NULJohannes Schindelin, Sep 28, 2007
  2. Daniel BarkalowSep 28, 2007
  3. Junio C HamanoSep 28, 2007
  4. Johannes SchindelinSep 28, 2007
  5. Pierre HabouzitSep 28, 2007
  6. Pierre HabouzitSep 28, 2007
  7. Daniel BarkalowSep 28, 2007
  8. Johannes SchindelinSep 28, 2007
  9. Junio C HamanoSep 28, 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.