2019-06-04 16:11:38 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-10-25 05:37:32 +08:00
|
|
|
/// Find &&/|| operations that include the same argument more than once
|
2018-08-04 00:32:11 +08:00
|
|
|
//# A common source of false positives is when the expression, or
|
|
|
|
//# another expresssion in the same && or || operation, performs a
|
|
|
|
//# side effect.
|
2010-10-25 05:37:32 +08:00
|
|
|
///
|
|
|
|
// Confidence: Moderate
|
2019-06-04 16:11:38 +08:00
|
|
|
// Copyright: (C) 2010 Nicolas Palix, DIKU.
|
|
|
|
// Copyright: (C) 2010 Julia Lawall, DIKU.
|
|
|
|
// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
|
2010-10-25 05:37:32 +08:00
|
|
|
// URL: http://coccinelle.lip6.fr/
|
|
|
|
// Comments:
|
2013-06-20 19:10:56 +08:00
|
|
|
// Options: --no-includes --include-headers
|
2010-10-25 05:37:32 +08:00
|
|
|
|
|
|
|
virtual context
|
|
|
|
virtual org
|
|
|
|
virtual report
|
|
|
|
|
|
|
|
@r expression@
|
|
|
|
expression E;
|
|
|
|
position p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
2018-08-04 00:32:11 +08:00
|
|
|
E@p || ... || E
|
2010-10-25 05:37:32 +08:00
|
|
|
|
|
2018-08-04 00:32:11 +08:00
|
|
|
E@p && ... && E
|
2010-10-25 05:37:32 +08:00
|
|
|
)
|
|
|
|
|
2018-08-04 00:32:11 +08:00
|
|
|
@bad@
|
|
|
|
expression r.E,e1,e2,fn;
|
|
|
|
position r.p;
|
|
|
|
assignment operator op;
|
|
|
|
@@
|
|
|
|
|
|
|
|
(
|
|
|
|
E@p
|
|
|
|
&
|
|
|
|
<+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+>
|
|
|
|
)
|
|
|
|
|
|
|
|
@depends on context && !bad@
|
|
|
|
expression r.E;
|
|
|
|
position r.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
*E@p
|
|
|
|
|
|
|
|
@script:python depends on org && !bad@
|
2010-10-25 05:37:32 +08:00
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
cocci.print_main("duplicated argument to && or ||",p)
|
|
|
|
|
2018-08-04 00:32:11 +08:00
|
|
|
@script:python depends on report && !bad@
|
2010-10-25 05:37:32 +08:00
|
|
|
p << r.p;
|
|
|
|
@@
|
|
|
|
|
|
|
|
coccilib.report.print_report(p[0],"duplicated argument to && or ||")
|