builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove()

The variables 'source', 'destination', and 'submodule_gitfile' are all of type "const char **", and an element of such an array is of "type const char *", but these memmove() calls were written as if these variables are of type "char **". Once these memmove() calls are fixed to use the correct type to compute the number of bytes to be moved, e.g. - memmove(source + i, source + i + 1, n * sizeof(char *)); + memmove(source + i, source + i + 1, n * sizeof(const char *)); existing contrib/coccinelle/array.cocci rules can recognize them as candidates for turning into MOVE_ARRAY(). While at it, use CALLOC_ARRAY() instead of xcalloc() to allocate the modes[] array that is involved in the change. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 9, 2022 at 18:33 UTC eee227ad8e759c0e7f625de3ee4458f85e4c9539
1 file changed +7 -9
builtin/mv.c
+7 -9
@@ -148,7 +148,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
148 die(_("index file corrupt"));
149
150 source = internal_prefix_pathspec(prefix, argv, argc, 0);
151 - modes = xcalloc(argc, sizeof(enum update_mode));
151 + CALLOC_ARRAY(modes, argc);
152 +
153 /*
154 * Keep trailing slash, needed to let
155 * "git mv file no-such-dir/" error out, except in the case
@@ -282,14 +283,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
283 remove_entry:
284 if (--argc > 0) {
285 int n = argc - i;
285 - memmove(source + i, source + i + 1,
286 - n * sizeof(char *));
287 - memmove(destination + i, destination + i + 1,
288 - n * sizeof(char *));
289 - memmove(modes + i, modes + i + 1,
290 - n * sizeof(enum update_mode));
291 - memmove(submodule_gitfile + i, submodule_gitfile + i + 1,
292 - n * sizeof(char *));
286 + MOVE_ARRAY(source + i, source + i + 1, n);
287 + MOVE_ARRAY(destination + i, destination + i + 1, n);
288 + MOVE_ARRAY(modes + i, modes + i + 1, n);
289 + MOVE_ARRAY(submodule_gitfile + i,
290 + submodule_gitfile + i + 1, n);
291 i--;
292 }
293 }