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:
René Scharfe
2017-02-25 11:30:03 +01:00
committed by Junio C Hamano
parent 3b9e3c2ced
commit 3f64699ffd
2 changed files with 17 additions and 1 deletions

View File

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