summaryrefslogtreecommitdiff
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-08-13 10:31:31 -0400
committerNick Mathewson <nickm@torproject.org>2014-08-13 10:39:56 -0400
commit5da821a8a3cfffc18f5a656852d98e69cff5dd8f (patch)
treefc9ec907b91de8f7dad39a6da1a777b397c01387 /scripts/coccinelle
parent19b137bc05d7414e478945c61f41409aa886462b (diff)
downloadtor-5da821a8a3cfffc18f5a656852d98e69cff5dd8f.tar.gz
tor-5da821a8a3cfffc18f5a656852d98e69cff5dd8f.zip
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.
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/calloc.cocci20
1 files changed, 20 insertions, 0 deletions
diff --git a/scripts/coccinelle/calloc.cocci b/scripts/coccinelle/calloc.cocci
new file mode 100644
index 0000000000..8a295eb4fd
--- /dev/null
+++ b/scripts/coccinelle/calloc.cocci
@@ -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)