Skip to content

Commit f01315e

Browse files
committed
Merge branch 'jc/builtin-mv-move-array'
Apply Coccinelle rule to turn raw memmove() into MOVE_ARRAY() cpp macro, which would improve maintainability and readability. * jc/builtin-mv-move-array: builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove()
2 parents 2c14392 + eee227a commit f01315e

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
@@ -187,7 +187,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
187187
die(_("index file corrupt"));
188188

189189
source = internal_prefix_pathspec(prefix, argv, argc, 0);
190-
modes = xcalloc(argc, sizeof(enum update_mode));
190+
CALLOC_ARRAY(modes, argc);
191+
191192
/*
192193
* Keep trailing slash, needed to let
193194
* "git mv file no-such-dir/" error out, except in the case
@@ -376,14 +377,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
376377
remove_entry:
377378
if (--argc > 0) {
378379
int n = argc - i;
379-
memmove(source + i, source + i + 1,
380-
n * sizeof(char *));
381-
memmove(destination + i, destination + i + 1,
382-
n * sizeof(char *));
383-
memmove(modes + i, modes + i + 1,
384-
n * sizeof(enum update_mode));
385-
memmove(submodule_gitfile + i, submodule_gitfile + i + 1,
386-
n * sizeof(char *));
380+
MOVE_ARRAY(source + i, source + i + 1, n);
381+
MOVE_ARRAY(destination + i, destination + i + 1, n);
382+
MOVE_ARRAY(modes + i, modes + i + 1, n);
383+
MOVE_ARRAY(submodule_gitfile + i,
384+
submodule_gitfile + i + 1, n);
387385
i--;
388386
}
389387
}

0 commit comments

Comments
 (0)