1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-08 12:26:13 +02: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

43 lines
513 B
Plaintext

@@
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);