Thread (20 messages) flat view 20 messages, 5 authors, 2016-06-15

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

From: "H. Peter Anvin" <hpa@zytor.com>
Date: 2016-06-15 22:42:06

Petr Baudis wrote:
quoted
quoted
-	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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help