summaryrefslogtreecommitdiff
path: root/tools/coccinelle
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2021-06-29 15:16:01 +0300
committerDonatas Abraitis <donatas.abraitis@gmail.com>2021-06-29 22:27:50 +0300
commit63f7a3b910282b62fcfbae165b9c9cbb2bca567c (patch)
tree81a24412bc659356eff2a5b507ee7f8b6d3cbf51 /tools/coccinelle
parent4953391b450351794a0cf646aa8bf9fea9869df8 (diff)
tools: Add coccinelle script for checking against XMALLOC/XCALLOC NULLs
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
Diffstat (limited to 'tools/coccinelle')
-rw-r--r--tools/coccinelle/xcalloc-xmalloc.cocci17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/coccinelle/xcalloc-xmalloc.cocci b/tools/coccinelle/xcalloc-xmalloc.cocci
new file mode 100644
index 0000000000..2a091d4cd9
--- /dev/null
+++ b/tools/coccinelle/xcalloc-xmalloc.cocci
@@ -0,0 +1,17 @@
+// No need checking against NULL for XMALLOC/XCALLOC.
+// If that happens, we have more problems with memory.
+
+@@
+type T;
+T *ptr;
+@@
+
+ptr =
+(
+XCALLOC(...)
+|
+XMALLOC(...)
+)
+...
+- if (ptr == NULL)
+- return ...;