]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Use MOVE_ARRAY
authorSZEDER Gábor <szeder.dev@gmail.com>
Mon, 22 Jan 2018 17:50:09 +0000 (18:50 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Jan 2018 19:32:51 +0000 (11:32 -0800)
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>
cache-tree.c
commit.c
diffcore-rename.c
dir.c
parse-options.c
read-cache.c
refs/ref-cache.c
replace_object.c
rerere.c

index e03e72c34a5c1fc618994ee63f38875d28d91886..18946aa458da3596e7aed3d5ce0af32e0458fccb 100644 (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;
 }
index cab8d4455bdbd6e4b87031613300be1112a19df5..7d0080180d9f0dc41c0ebbe4ed87a67a98659931 100644 (file)
--- a/commit.c
+++ b/commit.c
@@ -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;
 }
index 245e999fe5c6e9da62303423570d07aae5a88897..888a4b0189c00e3dcf99a3684afe88d62f7921b2 100644 (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]);
diff --git a/dir.c b/dir.c
index 7c4b45e30e0ac87527ff0ef3fd8c90670a1e2064..ce6e50d2a2399122ee5c12b18a0ebb8a07dc3f75 100644 (file)
--- a/dir.c
+++ b/dir.c
@@ -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;
index fca7159646c82cb9213e72afd94d8debc6bd4c51..d02eb8b0151626bab833489d7139a9be34209a32 100644 (file)
@@ -525,7 +525,7 @@ unknown:
 
 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;
 }
index 2eb81a66b941325dc339d61a0ab804a60cbb8be2..2e8c85c6861920416c4b5447195816aa5df1a4cc 100644 (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;
index 82c1cf90a7ef61cc8174bff5a9800af2ec8d7053..e90bd3e727fd0fcd5f6a99dde4fbac65b479f411 100644 (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--;
index f0b39f06d5dabc3c98c5c083458736a585b4cabb..3e49965d050829ad883e571d9b7c4596991aa974 100644 (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;
 }
index 1ce440f4bb84d001ff2b0ac1a67772f4bf5926c0..79203c6c1eae0db5515030b138e9e40e219af5f5 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -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);
        }