summaryrefslogtreecommitdiff
path: root/git-compat-util.h
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-08-11 13:26:57 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-08-11 13:26:57 -0700
commit32f90258bd510d84dfe8970211ec1427e9e327dc (patch)
tree6727e0574f5c648aec927e43545617b0c5fca32e /git-compat-util.h
parentMerge branch 'rs/bswap-ubsan-fix' (diff)
parentls-files: don't try to prune an empty index (diff)
downloadtgif-32f90258bd510d84dfe8970211ec1427e9e327dc.tar.xz
Merge branch 'rs/move-array'
Code clean-up. * rs/move-array: ls-files: don't try to prune an empty index apply: use COPY_ARRAY and MOVE_ARRAY in update_image() use MOVE_ARRAY add MOVE_ARRAY
Diffstat (limited to 'git-compat-util.h')
-rw-r--r--git-compat-util.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h
index db9c22de76..7d2c0ca759 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -828,6 +828,14 @@ static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
memcpy(dst, src, st_mult(size, n));
}
+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \
+ BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
+static inline void move_array(void *dst, const void *src, size_t n, size_t size)
+{
+ if (n)
+ memmove(dst, src, st_mult(size, n));
+}
+
/*
* These functions help you allocate structs with flex arrays, and copy
* the data directly into the array. For example, if you had: