summaryrefslogtreecommitdiffstats
path: root/tools/coccinelle
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2021-09-27 14:20:51 +0200
committerDonatas Abraitis <donatas.abraitis@gmail.com>2021-09-27 14:21:52 +0200
commit94ca37e0a9c9f7133e9b9ca3ec9d10303bca4e77 (patch)
tree0110b74884b01ea734433f81aae74997979f074d /tools/coccinelle
parentMerge pull request #9638 from proelbtn/fix-multipath-srv6-sid (diff)
downloadfrr-94ca37e0a9c9f7133e9b9ca3ec9d10303bca4e77.tar.xz
frr-94ca37e0a9c9f7133e9b9ca3ec9d10303bca4e77.zip
tools: Add coccinelle script to catch \n or \r at the end of zlog_*
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
Diffstat (limited to 'tools/coccinelle')
-rw-r--r--tools/coccinelle/zlog_no_newline.cocci20
1 files changed, 20 insertions, 0 deletions
diff --git a/tools/coccinelle/zlog_no_newline.cocci b/tools/coccinelle/zlog_no_newline.cocci
new file mode 100644
index 000000000..20cf9d2c7
--- /dev/null
+++ b/tools/coccinelle/zlog_no_newline.cocci
@@ -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))