mirror of
https://github.com/git/git.git
synced 2024-10-19 11:48:53 +02:00
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>
This commit is contained in:
parent
dc8c8deaa6
commit
eee227ad8e
16
builtin/mv.c
16
builtin/mv.c
@ -148,7 +148,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
|
|||||||
die(_("index file corrupt"));
|
die(_("index file corrupt"));
|
||||||
|
|
||||||
source = internal_prefix_pathspec(prefix, argv, argc, 0);
|
source = internal_prefix_pathspec(prefix, argv, argc, 0);
|
||||||
modes = xcalloc(argc, sizeof(enum update_mode));
|
CALLOC_ARRAY(modes, argc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keep trailing slash, needed to let
|
* Keep trailing slash, needed to let
|
||||||
* "git mv file no-such-dir/" error out, except in the case
|
* "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)
|
|||||||
remove_entry:
|
remove_entry:
|
||||||
if (--argc > 0) {
|
if (--argc > 0) {
|
||||||
int n = argc - i;
|
int n = argc - i;
|
||||||
memmove(source + i, source + i + 1,
|
MOVE_ARRAY(source + i, source + i + 1, n);
|
||||||
n * sizeof(char *));
|
MOVE_ARRAY(destination + i, destination + i + 1, n);
|
||||||
memmove(destination + i, destination + i + 1,
|
MOVE_ARRAY(modes + i, modes + i + 1, n);
|
||||||
n * sizeof(char *));
|
MOVE_ARRAY(submodule_gitfile + i,
|
||||||
memmove(modes + i, modes + i + 1,
|
submodule_gitfile + i + 1, n);
|
||||||
n * sizeof(enum update_mode));
|
|
||||||
memmove(submodule_gitfile + i, submodule_gitfile + i + 1,
|
|
||||||
n * sizeof(char *));
|
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user