mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Add a simple coccinelle script to replace malloc->calloc
Coccinelle is a semantic patching tool that can automatically change C code via semantic patching. This script also replaces realloc with reallocarray as appropriate.
This commit is contained in:
parent
19b137bc05
commit
5da821a8a3
20
scripts/coccinelle/calloc.cocci
Normal file
20
scripts/coccinelle/calloc.cocci
Normal file
@ -0,0 +1,20 @@
|
||||
// Use calloc or realloc as appropriate instead of multiply-and-alloc
|
||||
|
||||
@malloc_to_calloc@
|
||||
expression a,b;
|
||||
@@
|
||||
- tor_malloc(a * b)
|
||||
+ tor_calloc(a, b)
|
||||
|
||||
@malloc_zero_to_calloc@
|
||||
expression a, b;
|
||||
@@
|
||||
- tor_malloc_zero(a * b)
|
||||
+ tor_calloc(a, b)
|
||||
|
||||
@realloc_to_reallocarray@
|
||||
expression a, b;
|
||||
expression p;
|
||||
@@
|
||||
- tor_realloc(p, a * b)
|
||||
+ tor_reallocarray(p, a, b)
|
Loading…
Reference in New Issue
Block a user