diff mbox series

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

Message ID xmqqy1x531vp.fsf@gitster.g (mailing list archive)
State Superseded
Headers show
Series [v2] builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove() | expand

Commit Message

Junio C Hamano July 7, 2022, 5:52 a.m. UTC
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().

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin/mv.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/builtin/mv.c b/builtin/mv.c
index 83a465ba83..d599233057 100644
--- a/builtin/mv.c
+++ b/builtin/mv.c
@@ -282,14 +282,12 @@  int cmd_mv(int argc, const char **argv, const char *prefix)
 remove_entry:
 		if (--argc > 0) {
 			int n = argc - i;
-			memmove(source + i, source + i + 1,
-				n * sizeof(char *));
-			memmove(destination + i, destination + i + 1,
-				n * sizeof(char *));
+			MOVE_ARRAY(source + i, source + i + 1, n);
+			MOVE_ARRAY(destination + i, destination + i + 1, n);
 			memmove(modes + i, modes + i + 1,
 				n * sizeof(enum update_mode));
-			memmove(submodule_gitfile + i, submodule_gitfile + i + 1,
-				n * sizeof(char *));
+			MOVE_ARRAY(submodule_gitfile + i,
+				   submodule_gitfile + i + 1, n);
 			i--;
 		}
 	}