Skip to content

Commit eee227a

Browse files
committed
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 <[email protected]>
1 parent dc8c8de commit eee227a

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

builtin/mv.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
148148
die(_("index file corrupt"));
149149

150150
source = internal_prefix_pathspec(prefix, argv, argc, 0);
151-
modes = xcalloc(argc, sizeof(enum update_mode));
151+
CALLOC_ARRAY(modes, argc);
152+
152153
/*
153154
* Keep trailing slash, needed to let
154155
* "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)
282283
remove_entry:
283284
if (--argc > 0) {
284285
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);
293291
i--;
294292
}
295293
}

0 commit comments

Comments
 (0)