Subject: Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)

From: "H. Peter Anvin" <[email-masked]>
Date: Mon, 19 Sep 2005 17:42:47 -0700

Petr Baudis wrote:
>>>
>>>-	memcpy(path, git_dir, len);
>>>+	memcpy(path, git_dir, len-1);
>>>+	path[len] = 0;
>>>	copy_templates_1(path, len,
>>
>>Wrong!  You're not initializing path[len-1]!
> 
> 
> Oops, sorry. That's what you get when you want to make things marginally
> better. ;-) We indeed want to pass copy_templates_1() the trailing slash
> as well.
> 
> Let's just settle with the original patch then.
> 

But if len is the index of the '/', then you're not.

Think about it: the memcpy(path, git_dir, len) copies bytes 0..len-1. 
Thus you need to use path[len] = 0 to terminate.

If you want to copy len-1 characters, then you need to use path[len-1] = 0.

	-hpa