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