1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-19 12:56:08 +02:00

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>
This commit is contained in:
SZEDER Gábor 2018-01-22 18:50:09 +01:00 committed by Junio C Hamano
parent 8279ed033f
commit f919ffebed
9 changed files with 19 additions and 27 deletions

View File

@ -84,9 +84,8 @@ static struct cache_tree_sub *find_subtree(struct cache_tree *it,
down->namelen = pathlen;
if (pos < it->subtree_nr)
memmove(it->down + pos + 1,
it->down + pos,
sizeof(down) * (it->subtree_nr - pos - 1));
MOVE_ARRAY(it->down + pos + 1, it->down + pos,
it->subtree_nr - pos - 1);
it->down[pos] = down;
return down;
}

View File

@ -126,10 +126,8 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
ALLOC_GROW(commit_graft, commit_graft_nr + 1, commit_graft_alloc);
commit_graft_nr++;
if (pos < commit_graft_nr)
memmove(commit_graft + pos + 1,
commit_graft + pos,
(commit_graft_nr - pos - 1) *
sizeof(*commit_graft));
MOVE_ARRAY(commit_graft + pos + 1, commit_graft + pos,
commit_graft_nr - pos - 1);
commit_graft[pos] = graft;
return 0;
}

View File

@ -57,8 +57,8 @@ static int add_rename_dst(struct diff_filespec *two)
ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
rename_dst_nr++;
if (first < rename_dst_nr)
memmove(rename_dst + first + 1, rename_dst + first,
(rename_dst_nr - first - 1) * sizeof(*rename_dst));
MOVE_ARRAY(rename_dst + first + 1, rename_dst + first,
rename_dst_nr - first - 1);
rename_dst[first].two = alloc_filespec(two->path);
fill_filespec(rename_dst[first].two, &two->oid, two->oid_valid,
two->mode);
@ -98,8 +98,8 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
ALLOC_GROW(rename_src, rename_src_nr + 1, rename_src_alloc);
rename_src_nr++;
if (first < rename_src_nr)
memmove(rename_src + first + 1, rename_src + first,
(rename_src_nr - first - 1) * sizeof(*rename_src));
MOVE_ARRAY(rename_src + first + 1, rename_src + first,
rename_src_nr - first - 1);
rename_src[first].p = p;
rename_src[first].score = score;
return &(rename_src[first]);

4
dir.c
View File

@ -747,8 +747,8 @@ static struct untracked_cache_dir *lookup_untracked(struct untracked_cache *uc,
FLEX_ALLOC_MEM(d, name, name, len);
ALLOC_GROW(dir->dirs, dir->dirs_nr + 1, dir->dirs_alloc);
memmove(dir->dirs + first + 1, dir->dirs + first,
(dir->dirs_nr - first) * sizeof(*dir->dirs));
MOVE_ARRAY(dir->dirs + first + 1, dir->dirs + first,
dir->dirs_nr - first);
dir->dirs_nr++;
dir->dirs[first] = d;
return d;

View File

@ -525,7 +525,7 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
int parse_options_end(struct parse_opt_ctx_t *ctx)
{
memmove(ctx->out + ctx->cpidx, ctx->argv, ctx->argc * sizeof(*ctx->out));
MOVE_ARRAY(ctx->out + ctx->cpidx, ctx->argv, ctx->argc);
ctx->out[ctx->cpidx + ctx->argc] = NULL;
return ctx->cpidx + ctx->argc;
}

View File

@ -1217,9 +1217,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
/* Add it in.. */
istate->cache_nr++;
if (istate->cache_nr > pos + 1)
memmove(istate->cache + pos + 1,
istate->cache + pos,
(istate->cache_nr - pos - 1) * sizeof(ce));
MOVE_ARRAY(istate->cache + pos + 1, istate->cache + pos,
istate->cache_nr - pos - 1);
set_index_entry(istate, pos, ce);
istate->cache_changed |= CE_ENTRY_ADDED;
return 0;

View File

@ -238,10 +238,8 @@ int remove_entry_from_dir(struct ref_dir *dir, const char *refname)
return -1;
entry = dir->entries[entry_index];
memmove(&dir->entries[entry_index],
&dir->entries[entry_index + 1],
(dir->nr - entry_index - 1) * sizeof(*dir->entries)
);
MOVE_ARRAY(&dir->entries[entry_index],
&dir->entries[entry_index + 1], dir->nr - entry_index - 1);
dir->nr--;
if (dir->sorted > entry_index)
dir->sorted--;

View File

@ -44,10 +44,8 @@ static int register_replace_object(struct replace_object *replace,
ALLOC_GROW(replace_object, replace_object_nr + 1, replace_object_alloc);
replace_object_nr++;
if (pos < replace_object_nr)
memmove(replace_object + pos + 1,
replace_object + pos,
(replace_object_nr - pos - 1) *
sizeof(*replace_object));
MOVE_ARRAY(replace_object + pos + 1, replace_object + pos,
replace_object_nr - pos - 1);
replace_object[pos] = replace;
return 0;
}

View File

@ -159,8 +159,8 @@ static struct rerere_dir *find_rerere_dir(const char *hex)
ALLOC_GROW(rerere_dir, rerere_dir_nr + 1, rerere_dir_alloc);
/* ... and add it in. */
rerere_dir_nr++;
memmove(rerere_dir + pos + 1, rerere_dir + pos,
(rerere_dir_nr - pos - 1) * sizeof(*rerere_dir));
MOVE_ARRAY(rerere_dir + pos + 1, rerere_dir + pos,
rerere_dir_nr - pos - 1);
rerere_dir[pos] = rr_dir;
scan_rerere_dir(rr_dir);
}