summaryrefslogtreecommitdiff
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-09-16 10:57:00 -0400
committerNick Mathewson <nickm@torproject.org>2014-09-16 10:57:00 -0400
commitef9a0d204838768055194bd47acdb0074c2f13cb (patch)
treeb4536c7f79495fca681ba1ff7fe610e27f8695f0 /scripts/coccinelle
parent0bd220adcb82670893c85b1cc24d64e615855b4f (diff)
downloadtor-ef9a0d204838768055194bd47acdb0074c2f13cb.tar.gz
tor-ef9a0d204838768055194bd47acdb0074c2f13cb.zip
Add script to detect and remove unCish malloc-then-cast pattern
Also, apply it.
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/malloc_cast.cocci38
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/coccinelle/malloc_cast.cocci b/scripts/coccinelle/malloc_cast.cocci
new file mode 100644
index 0000000000..20321d4fd0
--- /dev/null
+++ b/scripts/coccinelle/malloc_cast.cocci
@@ -0,0 +1,38 @@
+@cast_malloc@
+expression e;
+type T;
+@@
+- (T *)tor_malloc(e)
++ tor_malloc(e)
+
+@cast_malloc_zero@
+expression e;
+type T;
+identifier func;
+@@
+- (T *)tor_malloc_zero(e)
++ tor_malloc_zero(e)
+
+@cast_calloc@
+expression a, b;
+type T;
+identifier func;
+@@
+- (T *)tor_calloc(a, b)
++ tor_calloc(a, b)
+
+@cast_realloc@
+expression e;
+expression p;
+type T;
+@@
+- (T *)tor_realloc(p, e)
++ tor_realloc(p, e)
+
+@cast_reallocarray@
+expression a,b;
+expression p;
+type T;
+@@
+- (T *)tor_reallocarray(p, a, b)
++ tor_reallocarray(p, a, b)