diff options
author | René Scharfe <l.s.r@web.de> | 2016-09-25 09:24:03 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-09-25 16:44:13 -0700 |
commit | 45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4 (patch) | |
tree | 83dffbe2e99b0fd98a286208a655012a86fb292b /contrib/coccinelle | |
parent | 60566cbb5890abc84fa18c56da70e35ace0b23bf (diff) | |
download | git-45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4.tar.gz git-45ccef87b3cc0ab09ec5fd1186aa0b33298ee8d4.tar.xz |
use COPY_ARRAY
Add a semantic patch for converting certain calls of memcpy(3) to
COPY_ARRAY() and apply that transformation to the code base. The result
is
shorter and safer code. For now only consider calls where source and
destination have the same type, or in other words: easy cases.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/coccinelle')
-rw-r--r-- | contrib/coccinelle/array.cocci | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/contrib/coccinelle/array.cocci b/contrib/coccinelle/array.cocci new file mode 100644 index 000000000..2d7f25d99 --- /dev/null +++ b/contrib/coccinelle/array.cocci @@ -0,0 +1,26 @@ +@@ +type T; +T *dst; +T *src; +expression n; +@@ +- memcpy(dst, src, n * sizeof(*dst)); ++ COPY_ARRAY(dst, src, n); + +@@ +type T; +T *dst; +T *src; +expression n; +@@ +- memcpy(dst, src, n * sizeof(*src)); ++ COPY_ARRAY(dst, src, n); + +@@ +type T; +T *dst; +T *src; +expression n; +@@ +- memcpy(dst, src, n * sizeof(T)); ++ COPY_ARRAY(dst, src, n); |