summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2017-07-15 19:36:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-07-17 21:54:53 (GMT)
commit578398071e45d296c3dc1de10acdbc15365e763f (patch)
treed49c040e24d00c7d1c706e4146e4de2bdae1fa5f /contrib
parentf3da2b79be9565779e4f76dc5812c68e156afdf0 (diff)
downloadgit-578398071e45d296c3dc1de10acdbc15365e763f.zip
git-578398071e45d296c3dc1de10acdbc15365e763f.tar.gz
git-578398071e45d296c3dc1de10acdbc15365e763f.tar.bz2
add MOVE_ARRAY
Similar to COPY_ARRAY (introduced in 60566cbb58), add a safe and convenient helper for moving potentially overlapping ranges of array entries. It infers the element size, multiplies automatically and safely to get the size in bytes, does a basic type safety check by comparing element sizes and unlike memmove(3) it supports NULL pointers iff 0 elements are to be moved. Also add a semantic patch to demonstrate the helper's intended usage. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib')
-rw-r--r--contrib/coccinelle/array.cocci17
1 files changed, 17 insertions, 0 deletions
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci
index 4ba98b7..c61d1ca 100644
--- a/contrib/coccinelle/array.cocci
+++ b/contrib/coccinelle/array.cocci
@@ -27,6 +27,23 @@ expression n;
@@
type T;
+T *dst;
+T *src;
+expression n;
+@@
+(
+- memmove(dst, src, (n) * sizeof(*dst));
++ MOVE_ARRAY(dst, src, n);
+|
+- memmove(dst, src, (n) * sizeof(*src));
++ MOVE_ARRAY(dst, src, n);
+|
+- memmove(dst, src, (n) * sizeof(T));
++ MOVE_ARRAY(dst, src, n);
+)
+
+@@
+type T;
T *ptr;
expression n;
@@