]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove()
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Jul 2022 01:33:54 +0000 (18:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Jul 2022 01:38:57 +0000 (18:38 -0700)
commiteee227ad8e759c0e7f625de3ee4458f85e4c9539
tree6b4f80af51bab63ed139ff4de3806423fa46252c
parentdc8c8deaa6b5847733bd7df011a4c7b7d1a64e0a
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>
builtin/mv.c