]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tools: Add coccinelle script for checking against XMALLOC/XCALLOC NULLs
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 29 Jun 2021 12:16:01 +0000 (15:16 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Tue, 29 Jun 2021 19:27:50 +0000 (22:27 +0300)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tools/coccinelle/xcalloc-xmalloc.cocci [new file with mode: 0644]

diff --git a/tools/coccinelle/xcalloc-xmalloc.cocci b/tools/coccinelle/xcalloc-xmalloc.cocci
new file mode 100644 (file)
index 0000000..2a091d4
--- /dev/null
@@ -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 ...;