]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Add a simple coccinelle script to replace malloc->calloc
authorNick Mathewson <nickm@torproject.org>
Wed, 13 Aug 2014 14:31:31 +0000 (10:31 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 13 Aug 2014 14:39:56 +0000 (10:39 -0400)
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 [new file with mode: 0644]

diff --git a/scripts/coccinelle/calloc.cocci b/scripts/coccinelle/calloc.cocci
new file mode 100644 (file)
index 0000000..8a295eb
--- /dev/null
@@ -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)