summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-08-06 08:34:24 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-08-06 08:34:24 +0200
commit919da09f2fa1c425695659f48111009bb4e42207 (patch)
tree56f87712b74249c960f65843edb961c0fc24a970
parent43623b9ccf588b3a0a76ec6450c20cc7dbef1974 (diff)
cocci: Add script to enforce the malloc usage as per cairo/CODING_STYLE
cairo CODING_STYLE guidelines require checking the argument of malloc for overflow and provide some utilities for common usage patterns such as (a*b), (a*b*c) and (a*b+c). Automatically replace malloc invocation of these expressions with the overflow-safe version.
-rw-r--r--malloc-coding-style.cocci27
1 files changed, 27 insertions, 0 deletions
diff --git a/malloc-coding-style.cocci b/malloc-coding-style.cocci
new file mode 100644
index 0000000..90cd4da
--- /dev/null
+++ b/malloc-coding-style.cocci
@@ -0,0 +1,27 @@
+// Apply the malloc replacements suggested in CODING_STYLE
+//
+// Cairo has some utility macros to check that the expressions used to
+// compute the argument of a malloc() call do not overflow.
+// CODING_STYLE indicates the replacements that should be done in
+// order to use these functions correctly.
+
+// malloc (n * size + k) => _cairo_malloc_ab_plus_c (n, size, k)
+@@
+expression n,size,k;
+@@
+-malloc ((n) * (size) + (k))
++_cairo_malloc_ab_plus_c (n, size, k)
+
+// malloc (a * b * size) => _cairo_malloc_abc (a, b, size)
+@@
+expression a,b,size;
+@@
+-malloc ((a) * (b) * (size))
++_cairo_malloc3 (a, b, size)
+
+// malloc (n * size) => _cairo_malloc_ab (n, size)
+@@
+expression n,size;
+@@
+-malloc ((n) * (size))
++_cairo_malloc_ab (n, size)