summaryrefslogtreecommitdiffstats
path: root/tools/coccinelle
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2021-06-29 14:16:01 +0200
committerDonatas Abraitis <donatas.abraitis@gmail.com>2021-06-29 21:27:50 +0200
commit63f7a3b910282b62fcfbae165b9c9cbb2bca567c (patch)
tree81a24412bc659356eff2a5b507ee7f8b6d3cbf51 /tools/coccinelle
parentbgpd: Avoid more assignments within checks (round 2) (diff)
downloadfrr-63f7a3b910282b62fcfbae165b9c9cbb2bca567c.tar.xz
frr-63f7a3b910282b62fcfbae165b9c9cbb2bca567c.zip
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 000000000..2a091d4cd
--- /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 ...;