1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-01 14:57:52 +01:00
git/contrib/coccinelle/array.cocci
René Scharfe 3f64699ffd cocci: use ALLOC_ARRAY
Add a semantic patch for using ALLOC_ARRAY to allocate arrays and apply
the transformation on the current source tree.  The macro checks for
multiplication overflow and infers the element size automatically; the
result is shorter and safer code.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-02-27 11:02:05 -08:00

42 lines
513 B
Text

@@
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);
@@
type T;
T *ptr;
expression n;
@@
- ptr = xmalloc(n * sizeof(*ptr));
+ ALLOC_ARRAY(ptr, n);
@@
type T;
T *ptr;
expression n;
@@
- ptr = xmalloc(n * sizeof(T));
+ ALLOC_ARRAY(ptr, n);