summaryrefslogtreecommitdiff
path: root/scripts/coccinelle/calloc.cocci
blob: fbda88e538491dbc8bc0de95c53ec13667fe3d31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Use calloc or realloc as appropriate instead of multiply-and-alloc

@malloc_to_calloc@
identifier f =~ "(tor_malloc|tor_malloc_zero)";
expression a;
constant b;
@@
- f(a * b)
+ tor_calloc(a, b)

@calloc_arg_order@
expression a;
type t;
@@
- tor_calloc(sizeof(t), a)
+ tor_calloc(a, sizeof(t))

@realloc_to_reallocarray@
expression a, b;
expression p;
@@
- tor_realloc(p, a * b)
+ tor_reallocarray(p, a, b)