1// SPDX-License-Identifier: GPL-2.0-only 2/// 3/// Catch strings ending in newline with (GE)NL_SET_ERR_MSG*. 4/// 5// Confidence: Very High 6// Copyright: (C) 2020 Intel Corporation 7// URL: https://coccinelle.gitlabpages.inria.fr/website 8// Options: --no-includes --include-headers 9 10virtual context 11virtual org 12virtual report 13 14@r depends on context || org || report@ 15expression e; 16constant m; 17position p; 18@@ 19 \(GENL_SET_ERR_MSG\|GENL_SET_ERR_MSG_FMT\|NL_SET_ERR_MSG\|NL_SET_ERR_MSG_MOD\| 20 NL_SET_ERR_MSG_FMT\|NL_SET_ERR_MSG_FMT_MOD\|NL_SET_ERR_MSG_WEAK\| 21 NL_SET_ERR_MSG_WEAK_MOD\|NL_SET_ERR_MSG_ATTR_POL\| 22 NL_SET_ERR_MSG_ATTR_POL_FMT\|NL_SET_ERR_MSG_ATTR\| 23 NL_SET_ERR_MSG_ATTR_FMT\)(e,m@p,...) 24 25@script:python@ 26m << r.m; 27@@ 28 29if not m.endswith("\\n\""): 30 cocci.include_match(False) 31 32@r1 depends on r@ 33identifier fname; 34expression r.e; 35constant r.m; 36position r.p; 37@@ 38 fname(e,m@p,...) 39 40//---------------------------------------------------------- 41// For context mode 42//---------------------------------------------------------- 43 44@depends on context && r@ 45identifier r1.fname; 46expression r.e; 47constant r.m; 48@@ 49* fname(e,m,...) 50 51//---------------------------------------------------------- 52// For org mode 53//---------------------------------------------------------- 54 55@script:python depends on org@ 56fname << r1.fname; 57m << r.m; 58p << r.p; 59@@ 60 61if m.endswith("\\n\""): 62 msg="WARNING avoid newline at end of message in %s" % (fname) 63 msg_safe=msg.replace("[","@(").replace("]",")") 64 coccilib.org.print_todo(p[0], msg_safe) 65 66//---------------------------------------------------------- 67// For report mode 68//---------------------------------------------------------- 69 70@script:python depends on report@ 71fname << r1.fname; 72m << r.m; 73p << r.p; 74@@ 75 76if m.endswith("\\n\""): 77 msg="WARNING avoid newline at end of message in %s" % (fname) 78 coccilib.report.print_report(p[0], msg) 79