summaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/misc/boolreturn.cocci
blob: 29d2bf41e95d17fbc76f574dbd3f5e1b1d19792a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: GPL-2.0
/// Return statements in functions returning bool should use
/// true/false instead of 1/0.
//
// Confidence: High
// Options: --no-includes --include-headers

virtual patch
virtual report
virtual context

@r1 depends on patch@
identifier fn;
typedef bool;
symbol false;
symbol true;
@@

bool fn ( ... )
{
<...
return
(
- 0
+ false
|
- 1
+ true
)
  ;
...>
}

@r2 depends on report || context@
identifier fn;
position p;
@@

bool fn ( ... )
{
<...
return
(
* 0@p
|
* 1@p
)
  ;
...>
}


@script:python depends on report@
p << r2.p;
fn << r2.fn;
@@

msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn
coccilib.report.print_report(p[0], msg)