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

From: H. Peter Anvin <hpa@zytor.com>
Date: 2005-09-20 10:42:47
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
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Tue Sep 20 10:43:55 2005

This archive was generated by hypermail 2.1.8 : 2005-09-20 10:43:57 EST