[tor-commits] [tor/master] Add script to detect and remove unCish malloc-then-cast pattern
nickm at torproject.org
nickm at torproject.org
Tue Sep 16 15:11:54 UTC 2014
commit ef9a0d204838768055194bd47acdb0074c2f13cb
Author: Nick Mathewson <nickm at torproject.org>
Date: Tue Sep 16 10:57:00 2014 -0400
Add script to detect and remove unCish malloc-then-cast pattern
Also, apply it.
---
scripts/coccinelle/malloc_cast.cocci | 38 ++++++++++++++++++++++++++++++++++
src/or/circuitstats.c | 2 +-
2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/scripts/coccinelle/malloc_cast.cocci b/scripts/coccinelle/malloc_cast.cocci
new file mode 100644
index 0000000..20321d4
--- /dev/null
+++ b/scripts/coccinelle/malloc_cast.cocci
@@ -0,0 +1,38 @@
+ at cast_malloc@
+expression e;
+type T;
+@@
+- (T *)tor_malloc(e)
++ tor_malloc(e)
+
+ at cast_malloc_zero@
+expression e;
+type T;
+identifier func;
+@@
+- (T *)tor_malloc_zero(e)
++ tor_malloc_zero(e)
+
+ at cast_calloc@
+expression a, b;
+type T;
+identifier func;
+@@
+- (T *)tor_calloc(a, b)
++ tor_calloc(a, b)
+
+ at cast_realloc@
+expression e;
+expression p;
+type T;
+@@
+- (T *)tor_realloc(p, e)
++ tor_realloc(p, e)
+
+ at cast_reallocarray@
+expression a,b;
+expression p;
+type T;
+@@
+- (T *)tor_reallocarray(p, a, b)
++ tor_reallocarray(p, a, b)
diff --git a/src/or/circuitstats.c b/src/or/circuitstats.c
index 88a1f9b..c24259c 100644
--- a/src/or/circuitstats.c
+++ b/src/or/circuitstats.c
@@ -691,7 +691,7 @@ circuit_build_times_get_xm(circuit_build_times_t *cbt)
if (cbt->total_build_times < CBT_NCIRCUITS_TO_OBSERVE)
num_modes = 1;
- nth_max_bin = (build_time_t*)tor_calloc(num_modes, sizeof(build_time_t));
+ nth_max_bin = tor_calloc(num_modes, sizeof(build_time_t));
/* Determine the N most common build times */
for (i = 0; i < nbins; i++) {
More information about the tor-commits
mailing list