Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH] git-mv: Fix error with multiple sources.

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:05

"David Rydh" [off-list ref] writes:
quoted hunk
diff --git a/builtin-mv.c b/builtin-mv.c
index 8247186..1c1f8be 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -27,7 +27,7 @@ static const char **copy_pathspec(const char *prefix, const char **pathspec,
 		if (length > 0 && is_dir_sep(result[i][length - 1]))
 			result[i] = xmemdupz(result[i], length - 1);
 		if (base_name)
-			result[i] = basename((char *)result[i]);
+			result[i] = xstrdup(basename((char *)result[i]));
 	}
 	return get_pathspec(prefix, result);
 }
Given that basename(3) is allowed to modify its parameter, I think the
above code is still not portable.  casting constness away and feeding
result[i], especially when we didn't obtain our own copy by calling
xmemdupz(), is especially problematic.

Perhaps something ugly like this?

	for (i = 0; i < count; i++) {
		int length = strlen(result[i]);
		int to_copy = length;
                while (to_copy > 0 && is_dir_sep(result[i][to_copy - 1]))
			to_copy--;
		if (to_copy != length || basename) {
                	char *it = xmemdupz(result[i], to_copy);
                        result[i] = base_name ? strdup(basename(it)) : it;
		}
	}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help