summary refs log tree commit diff
path: root/notes-merge.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-07-15 22:00:45 +0200
committerJunio C Hamano <gitster@pobox.com>2017-07-17 14:54:56 -0700
commitf331ab9d4cb21942dcde6d879aaca6a1784e8cb6 (patch)
tree64203c98b322d7b468b2649df734a2a3ea443fc1 /notes-merge.c
parent578398071e45d296c3dc1de10acdbc15365e763f (diff)
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 'notes-merge.c')
-rw-r--r--notes-merge.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/notes-merge.c b/notes-merge.c
index 70e3fbeefb..c12b354f10 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -99,8 +99,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(
 	else {
 		*occupied = 0;
 		if (insert_new && i < len) {
-			memmove(list + i + 1, list + i,
-				(len - i) * sizeof(struct notes_merge_pair));
+			MOVE_ARRAY(list + i + 1, list + i, len - i);
 			memset(list + i, 0, sizeof(struct notes_merge_pair));
 		}
 	}