3f64699ffd
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>
43 lines
513 B
Plaintext
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);
|