Use MOVE_ARRAY

Use the helper macro MOVE_ARRAY to move arrays. This is shorter and safer, as it automatically infers the size of elements. Patch generated by Coccinelle and contrib/coccinelle/array.cocci in Travis CI's static analysis build job. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

SZEDER Gábor committed Jan 22, 2018 at 18:50 UTC f919ffebed3c570bf3c2a5f36444527ea5df42de
9 files changed +19 -27
cache-tree.c
+2 -3
@@ -84,9 +84,8 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
84 down->namelen = pathlen;
85
86 if (pos < it->subtree_nr)
87 - memmove(it->down + pos + 1,
88 - it->down + pos,
89 - sizeof(down) * (it->subtree_nr - pos - 1));
87 + MOVE_ARRAY(it->down + pos + 1, it->down + pos,
88 + it->subtree_nr - pos - 1);
89 it->down[pos] = down;
90 return down;
91 }
commit.c
+2 -4
@@ -126,10 +126,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
126 ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
127 commit_graft_nr++;
128 if (pos < commit_graft_nr)
129 - memmove(commit_graft + pos + 1,
130 - commit_graft + pos,
131 - (commit_graft_nr - pos - 1) *
132 - sizeof(*commit_graft));
129 + MOVE_ARRAY(commit_graft + pos + 1, commit_graft + pos,
130 + commit_graft_nr - pos - 1);
131 commit_graft[pos] = graft;
132 return 0;
133 }
diffcore-rename.c
+4 -4
@@ -57,8 +57,8 @@ static int add_rename_dst(struct diff_filespec *two)
57 ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
58 rename_dst_nr++;
59 if (first < rename_dst_nr)
60 - memmove(rename_dst + first + 1, rename_dst + first,
61 - (rename_dst_nr - first - 1) * sizeof(*rename_dst));
60 + MOVE_ARRAY(rename_dst + first + 1, rename_dst + first,
61 + rename_dst_nr - first - 1);
62 rename_dst[first].two = alloc_filespec(two->path);
63 fill_filespec(rename_dst[first].two, &two->oid, two->oid_valid,
64 two->mode);
@@ -98,8 +98,8 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
98 ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
99 rename_src_nr++;
100 if (first < rename_src_nr)
101 - memmove(rename_src + first + 1, rename_src + first,
102 - (rename_src_nr - first - 1) * sizeof(*rename_src));
101 + MOVE_ARRAY(rename_src + first + 1, rename_src + first,
102 + rename_src_nr - first - 1);
103 rename_src[first].p = p;
104 rename_src[first].score = score;
105 return &(rename_src[first]);
dir.c
+2 -2
@@ -747,8 +747,8 @@ static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc,
747 FLEX_ALLOC_MEM(d, name, name, len);
748
749 ALLOC_GROW(dir->dirs, dir->dirs_nr + 1, dir->dirs_alloc);
750 - memmove(dir->dirs + first + 1, dir->dirs + first,
751 - (dir->dirs_nr - first) * sizeof(*dir->dirs));
750 + MOVE_ARRAY(dir->dirs + first + 1, dir->dirs + first,
751 + dir->dirs_nr - first);
752 dir->dirs_nr++;
753 dir->dirs[first] = d;
754 return d;
parse-options.c
+1 -1
@@ -525,7 +525,7 @@ unknown:
525
526 int parse_options_end(struct parse_opt_ctx_t *ctx)
527 {
528 - memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
528 + MOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc);
529 ctx->out[ctx->cpidx + ctx->argc] = NULL;
530 return ctx->cpidx + ctx->argc;
531 }
read-cache.c
+2 -3
@@ -1217,9 +1217,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
1217 /* Add it in.. */
1218 istate->cache_nr++;
1219 if (istate->cache_nr > pos + 1)
1220 - memmove(istate->cache + pos + 1,
1221 - istate->cache + pos,
1222 - (istate->cache_nr - pos - 1) * sizeof(ce));
1220 + MOVE_ARRAY(istate->cache + pos + 1, istate->cache + pos,
1221 + istate->cache_nr - pos - 1);
1222 set_index_entry(istate, pos, ce);
1223 istate->cache_changed |= CE_ENTRY_ADDED;
1224 return 0;
refs/ref-cache.c
+2 -4
@@ -238,10 +238,8 @@ int remove_entry_from_dir(struct ref_dir *dir, const char *refname)
238 return -1;
239 entry = dir->entries[entry_index];
240
241 - memmove(&dir->entries[entry_index],
242 - &dir->entries[entry_index + 1],
243 - (dir->nr - entry_index - 1) * sizeof(*dir->entries)
244 - );
241 + MOVE_ARRAY(&dir->entries[entry_index],
242 + &dir->entries[entry_index + 1], dir->nr - entry_index - 1);
243 dir->nr--;
244 if (dir->sorted > entry_index)
245 dir->sorted--;
replace_object.c
+2 -4
@@ -44,10 +44,8 @@ static int register_replace_object(struct replace_object *replace,
44 ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
45 replace_object_nr++;
46 if (pos < replace_object_nr)
47 - memmove(replace_object + pos + 1,
48 - replace_object + pos,
49 - (replace_object_nr - pos - 1) *
50 - sizeof(*replace_object));
47 + MOVE_ARRAY(replace_object + pos + 1, replace_object + pos,
48 + replace_object_nr - pos - 1);
49 replace_object[pos] = replace;
50 return 0;
51 }
rerere.c
+2 -2
@@ -159,8 +159,8 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
159 ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
160 /* ... and add it in. */
161 rerere_dir_nr++;
162 - memmove(rerere_dir + pos + 1, rerere_dir + pos,
163 - (rerere_dir_nr - pos - 1) * sizeof(*rerere_dir));
162 + MOVE_ARRAY(rerere_dir + pos + 1, rerere_dir + pos,
163 + rerere_dir_nr - pos - 1);
164 rerere_dir[pos] = rr_dir;
165 scan_rerere_dir(rr_dir);
166 }