]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add script to detect and remove unCish malloc-then-cast pattern
authorNick Mathewson <nickm@torproject.org>
Tue, 16 Sep 2014 14:57:00 +0000 (10:57 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 16 Sep 2014 14:57:00 +0000 (10:57 -0400)
Also, apply it.

scripts/coccinelle/malloc_cast.cocci [new file with mode: 0644]
src/or/circuitstats.c

diff --git a/scripts/coccinelle/malloc_cast.cocci b/scripts/coccinelle/malloc_cast.cocci
new file mode 100644 (file)
index 0000000..20321d4
--- /dev/null
@@ -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)
index 88a1f9b46c95bb91322efaa19d00da4c57c4c743..c24259c22c619e1e9a038ac4ba383aa23e57ae3d 100644 (file)
@@ -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++) {