doubletest.cocci 1.09 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0-only
2
/// Find &&/|| operations that include the same argument more than once
3 4 5
//# A common source of false positives is when the expression, or
//# another expresssion in the same && or || operation, performs a
//# side effect.
6 7
///
// Confidence: Moderate
8 9 10
// Copyright: (C) 2010 Nicolas Palix, DIKU.
// Copyright: (C) 2010 Julia Lawall, DIKU.
// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
Julia Lawall's avatar
Julia Lawall committed
11
// URL: https://coccinelle.gitlabpages.inria.fr/website
12
// Comments:
13
// Options: --no-includes --include-headers
14 15 16 17 18 19 20 21 22 23 24

virtual context
virtual org
virtual report

@r expression@
expression E;
position p;
@@

(
25
 E@p || ... || E
26
|
27
 E@p && ... && E
28 29
)

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
@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@
50 51 52 53 54
p << r.p;
@@

cocci.print_main("duplicated argument to && or ||",p)

55
@script:python depends on report && !bad@
56 57 58 59
p << r.p;
@@

coccilib.report.print_report(p[0],"duplicated argument to && or ||")