git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] alloc_ref(): allow for trailing NUL
@ 2007-09-28  2:57 Johannes Schindelin
  2007-09-28  5:03 ` Daniel Barkalow
  0 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2007-09-28  2:57 UTC (permalink / raw)
  To: gitster, git


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

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

end of thread, other threads:[~2007-09-28 18:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-28  2:57 [PATCH] alloc_ref(): allow for trailing NUL Johannes Schindelin
2007-09-28  5:03 ` Daniel Barkalow
2007-09-28  8:46   ` Junio C Hamano
2007-09-28 12:01     ` Johannes Schindelin
2007-09-28 12:41       ` Pierre Habouzit
2007-09-28 13:13         ` Pierre Habouzit
2007-09-28 15:44       ` Daniel Barkalow
2007-09-28 16:11         ` Johannes Schindelin
2007-09-28 18:08           ` Junio C Hamano

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