Debian Codegraph @

scripts/coccinelle/misc/newline_in_nl_msg.cocci

raw
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
10 virtual context
11 virtual org
12 virtual report
13
14 @r depends on context || org || report@
15 expression e;
16 constant m;
17 position 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@
26 m << r.m;
27 @@
28
29 if not m.endswith("\\n\""):
30 cocci.include_match(False)
31
32 @r1 depends on r@
33 identifier fname;
34 expression r.e;
35 constant r.m;
36 position r.p;
37 @@
38 fname(e,m@p,...)
39
40 //----------------------------------------------------------
41 // For context mode
42 //----------------------------------------------------------
43
44 @depends on context && r@
45 identifier r1.fname;
46 expression r.e;
47 constant r.m;
48 @@
49 * fname(e,m,...)
50
51 //----------------------------------------------------------
52 // For org mode
53 //----------------------------------------------------------
54
55 @script:python depends on org@
56 fname << r1.fname;
57 m << r.m;
58 p << r.p;
59 @@
60
61 if 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@
71 fname << r1.fname;
72 m << r.m;
73 p << r.p;
74 @@
75
76 if m.endswith("\\n\""):
77 msg="WARNING avoid newline at end of message in %s" % (fname)
78 coccilib.report.print_report(p[0], msg)