Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// Catch strings ending in newline with GENL_SET_ERR_MSG, NL_SET_ERR_MSG,
0004 /// NL_SET_ERR_MSG_MOD.
0005 ///
0006 // Confidence: Very High
0007 // Copyright: (C) 2020 Intel Corporation
0008 // URL: https://coccinelle.gitlabpages.inria.fr/website
0009 // Options: --no-includes --include-headers
0010 
0011 virtual context
0012 virtual org
0013 virtual report
0014 
0015 @r depends on context || org || report@
0016 expression e;
0017 constant m;
0018 position p;
0019 @@
0020   \(GENL_SET_ERR_MSG\|NL_SET_ERR_MSG\|NL_SET_ERR_MSG_MOD\)(e,m@p)
0021 
0022 @script:python@
0023 m << r.m;
0024 @@
0025 
0026 if not m.endswith("\\n\""):
0027         cocci.include_match(False)
0028 
0029 @r1 depends on r@
0030 identifier fname;
0031 expression r.e;
0032 constant r.m;
0033 position r.p;
0034 @@
0035   fname(e,m@p)
0036 
0037 //----------------------------------------------------------
0038 //  For context mode
0039 //----------------------------------------------------------
0040 
0041 @depends on context && r@
0042 identifier r1.fname;
0043 expression r.e;
0044 constant r.m;
0045 @@
0046 * fname(e,m)
0047 
0048 //----------------------------------------------------------
0049 //  For org mode
0050 //----------------------------------------------------------
0051 
0052 @script:python depends on org@
0053 fname << r1.fname;
0054 m << r.m;
0055 p << r.p;
0056 @@
0057 
0058 if m.endswith("\\n\""):
0059         msg="WARNING avoid newline at end of message in %s" % (fname)
0060         msg_safe=msg.replace("[","@(").replace("]",")")
0061         coccilib.org.print_todo(p[0], msg_safe)
0062 
0063 //----------------------------------------------------------
0064 //  For report mode
0065 //----------------------------------------------------------
0066 
0067 @script:python depends on report@
0068 fname << r1.fname;
0069 m << r.m;
0070 p << r.p;
0071 @@
0072 
0073 if m.endswith("\\n\""):
0074         msg="WARNING avoid newline at end of message in %s" % (fname)
0075         coccilib.report.print_report(p[0], msg)