0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// Find &&/|| operations that include the same argument more than once
0003 //# A common source of false positives is when the expression, or
0004 //# another expresssion in the same && or || operation, performs a
0005 //# side effect.
0006 ///
0007 // Confidence: Moderate
0008 // Copyright: (C) 2010 Nicolas Palix, DIKU.
0009 // Copyright: (C) 2010 Julia Lawall, DIKU.
0010 // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
0011 // URL: https://coccinelle.gitlabpages.inria.fr/website
0012 // Comments:
0013 // Options: --no-includes --include-headers
0014
0015 virtual context
0016 virtual org
0017 virtual report
0018
0019 @r expression@
0020 expression E;
0021 position p;
0022 @@
0023
0024 (
0025 E@p || ... || E
0026 |
0027 E@p && ... && E
0028 )
0029
0030 @bad@
0031 expression r.E,e1,e2,fn;
0032 position r.p;
0033 assignment operator op;
0034 @@
0035
0036 (
0037 E@p
0038 &
0039 <+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+>
0040 )
0041
0042 @depends on context && !bad@
0043 expression r.E;
0044 position r.p;
0045 @@
0046
0047 *E@p
0048
0049 @script:python depends on org && !bad@
0050 p << r.p;
0051 @@
0052
0053 cocci.print_main("duplicated argument to && or ||",p)
0054
0055 @script:python depends on report && !bad@
0056 p << r.p;
0057 @@
0058
0059 coccilib.report.print_report(p[0],"duplicated argument to && or ||")