Skip to content

Commit f919ffe

Browse files
szedergitster
authored andcommitted
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>
1 parent 8279ed0 commit f919ffe

File tree

9 files changed

+19
-27
lines changed

9 files changed

+19
-27
lines changed

cache-tree.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
8484
down->namelen = pathlen;
8585

8686
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);
9089
it->down[pos] = down;
9190
return down;
9291
}

commit.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
126126
ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
127127
commit_graft_nr++;
128128
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);
133131
commit_graft[pos] = graft;
134132
return 0;
135133
}

diffcore-rename.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ static int add_rename_dst(struct diff_filespec *two)
5757
ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
5858
rename_dst_nr++;
5959
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);
6262
rename_dst[first].two = alloc_filespec(two->path);
6363
fill_filespec(rename_dst[first].two, &two->oid, two->oid_valid,
6464
two->mode);
@@ -98,8 +98,8 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
9898
ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
9999
rename_src_nr++;
100100
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);
103103
rename_src[first].p = p;
104104
rename_src[first].score = score;
105105
return &(rename_src[first]);

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,8 @@ static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc,
747747
FLEX_ALLOC_MEM(d, name, name, len);
748748

749749
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);
752752
dir->dirs_nr++;
753753
dir->dirs[first] = d;
754754
return d;

parse-options.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
525525

526526
int parse_options_end(struct parse_opt_ctx_t *ctx)
527527
{
528-
memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
528+
MOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc);
529529
ctx->out[ctx->cpidx + ctx->argc] = NULL;
530530
return ctx->cpidx + ctx->argc;
531531
}

read-cache.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,9 +1217,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
12171217
/* Add it in.. */
12181218
istate->cache_nr++;
12191219
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);
12231222
set_index_entry(istate, pos, ce);
12241223
istate->cache_changed |= CE_ENTRY_ADDED;
12251224
return 0;

refs/ref-cache.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,8 @@ int remove_entry_from_dir(struct ref_dir *dir, const char *refname)
238238
return -1;
239239
entry = dir->entries[entry_index];
240240

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);
245243
dir->nr--;
246244
if (dir->sorted > entry_index)
247245
dir->sorted--;

replace_object.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,8 @@ static int register_replace_object(struct replace_object *replace,
4444
ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
4545
replace_object_nr++;
4646
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);
5149
replace_object[pos] = replace;
5250
return 0;
5351
}

rerere.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
159159
ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
160160
/* ... and add it in. */
161161
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);
164164
rerere_dir[pos] = rr_dir;
165165
scan_rerere_dir(rr_dir);
166166
}

0 commit comments

Comments
 (0)