Re: [PATCH] Fix git-init-db creating crap directories (zeroth try)
- From
- H. Peter Anvin <hpa@zytor.com>
- Date
- Sep 20, 2005, 00:42 UTC
- Message-ID
- <432F5B07.2060803@zytor.com>
- In-Reply-To
- <20050920001949.GL18320@pasky.or.cz>
Petr Baudis wrote:
Show 15 quoted lines
>>> >>>- 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