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>
This commit is contained in:
parent
3b9e3c2ced
commit
3f64699ffd
@ -24,3 +24,19 @@ 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);
|
||||
|
@ -175,7 +175,7 @@ struct worktree **get_worktrees(unsigned flags)
|
||||
struct dirent *d;
|
||||
int counter = 0, alloc = 2;
|
||||
|
||||
list = xmalloc(alloc * sizeof(struct worktree *));
|
||||
ALLOC_ARRAY(list, alloc);
|
||||
|
||||
list[counter++] = get_main_worktree();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user