[tor-commits] [tor/master] Add a simple coccinelle script to replace malloc->calloc

nickm at torproject.org nickm at torproject.org
Wed Aug 13 19:02:14 UTC 2014


commit 5da821a8a3cfffc18f5a656852d98e69cff5dd8f
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Aug 13 10:31:31 2014 -0400

    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.
---
 scripts/coccinelle/calloc.cocci |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/scripts/coccinelle/calloc.cocci b/scripts/coccinelle/calloc.cocci
new file mode 100644
index 0000000..8a295eb
--- /dev/null
+++ b/scripts/coccinelle/calloc.cocci
@@ -0,0 +1,20 @@
+// Use calloc or realloc as appropriate instead of multiply-and-alloc
+
+ at malloc_to_calloc@
+expression a,b;
+@@
+- tor_malloc(a * b)
++ tor_calloc(a, b)
+
+ at malloc_zero_to_calloc@
+expression a, b;
+@@
+- tor_malloc_zero(a * b)
++ tor_calloc(a, b)
+
+ at realloc_to_reallocarray@
+expression a, b;
+expression p;
+@@
+- tor_realloc(p, a * b)
++ tor_reallocarray(p, a, b)





More information about the tor-commits mailing list