]> git.puffer.fish Git - mirror/frr.git/commitdiff
tools: Add coccinelle script to catch \n or \r at the end of zlog_* 9677/head
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Mon, 27 Sep 2021 12:20:51 +0000 (15:20 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Mon, 27 Sep 2021 12:21:52 +0000 (15:21 +0300)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
tools/coccinelle/zlog_no_newline.cocci [new file with mode: 0644]

diff --git a/tools/coccinelle/zlog_no_newline.cocci b/tools/coccinelle/zlog_no_newline.cocci
new file mode 100644 (file)
index 0000000..20cf9d2
--- /dev/null
@@ -0,0 +1,20 @@
+// zlog_* should not have \n or \r at the end usually.
+// spatch --sp-file tools/coccinelle/zlog_no_newline.cocci --macro-file tools/cocci.h ./ 2>/dev/null
+
+@r@
+expression fmt;
+identifier func =~ "zlog_";
+position p;
+@@
+(
+  func(fmt)@p
+|
+  func(fmt, ...)@p
+)
+
+@script:python@
+fmt << r.fmt;
+p << r.p;
+@@
+if "\\n" in str(fmt) or "\\r" in str(fmt):
+    print("Newline in logging function detected %s:%s:%s:%s" % (p[0].file, p[0].line, p[0].column, fmt))