summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-07-15 20:00:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-07-17 21:54:56 (GMT)
commitf331ab9d4cb21942dcde6d879aaca6a1784e8cb6 (patch)
tree64203c98b322d7b468b2649df734a2a3ea443fc1 /commit.c
parent578398071e45d296c3dc1de10acdbc15365e763f (diff)
downloadgit-f331ab9d4cb21942dcde6d879aaca6a1784e8cb6.zip
git-f331ab9d4cb21942dcde6d879aaca6a1784e8cb6.tar.gz
git-f331ab9d4cb21942dcde6d879aaca6a1784e8cb6.tar.bz2
use MOVE_ARRAY
Simplify the code for moving members inside of an array and make it more robust by using the helper macro MOVE_ARRAY. It calculates the size based on the specified number of elements for us and supports NULL pointers when that number is zero. Raw memmove(3) calls with NULL can cause the compiler to (over-eagerly) optimize out later NULL checks. This patch was generated with contrib/coccinelle/array.cocci and spatch (Coccinelle). Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/commit.c b/commit.c
index cbfd689..d3150d6 100644
--- a/commit.c
+++ b/commit.c
@@ -223,9 +223,8 @@ int unregister_shallow(const struct object_id *oid)
if (pos < 0)
return -1;
if (pos + 1 < commit_graft_nr)
- memmove(commit_graft + pos, commit_graft + pos + 1,
- sizeof(struct commit_graft *)
- * (commit_graft_nr - pos - 1));
+ MOVE_ARRAY(commit_graft + pos, commit_graft + pos + 1,
+ commit_graft_nr - pos - 1);
commit_graft_nr--;
return 0;
}