]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
DEV: coccinelle: Add xalloc_size.cocci
authorTim Duesterhus <tim@bastelstu.be>
Wed, 15 Sep 2021 11:58:45 +0000 (13:58 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 17 Sep 2021 15:22:05 +0000 (17:22 +0200)
This commits the Coccinelle patch to clean up sizeof handling for malloc/calloc.

dev/coccinelle/xalloc_size.cocci [new file with mode: 0644]

diff --git a/dev/coccinelle/xalloc_size.cocci b/dev/coccinelle/xalloc_size.cocci
new file mode 100644 (file)
index 0000000..80808e3
--- /dev/null
@@ -0,0 +1,41 @@
+@@
+type T;
+expression E;
+expression t;
+@@
+
+(
+  t = calloc(E, sizeof(*t))
+|
+- t = calloc(E, sizeof(T))
++ t = calloc(E, sizeof(*t))
+)
+
+@@
+type T;
+T *x;
+@@
+
+  x = malloc(
+- sizeof(T)
++ sizeof(*x)
+  )
+
+@@
+type T;
+T *x;
+@@
+
+  x = calloc(1,
+- sizeof(T)
++ sizeof(*x)
+  )
+
+@@
+@@
+
+  calloc(
++ 1,
+  ...
+- ,1
+  )