578398071e
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>
60 lines
767 B
Plaintext
60 lines
767 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 *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;
|
|
@@
|
|
- ptr = xmalloc(n * sizeof(*ptr));
|
|
+ ALLOC_ARRAY(ptr, n);
|
|
|
|
@@
|
|
type T;
|
|
T *ptr;
|
|
expression n;
|
|
@@
|
|
- ptr = xmalloc(n * sizeof(T));
|
|
+ ALLOC_ARRAY(ptr, n);
|