Linux Audio

Check our new training course

Loading...
v4.6
 
 1/// Return statements in functions returning bool should use
 2/// true/false instead of 1/0.
 3//
 4// Confidence: High
 5// Options: --no-includes --include-headers
 6
 7virtual patch
 8virtual report
 9virtual context
10
11@r1 depends on patch@
12identifier fn;
13typedef bool;
14symbol false;
15symbol true;
16@@
17
18bool fn ( ... )
19{
20<...
21return
22(
23- 0
24+ false
25|
26- 1
27+ true
28)
29  ;
30...>
31}
32
33@r2 depends on report || context@
34identifier fn;
35position p;
36@@
37
38bool fn ( ... )
39{
40<...
41return
42(
43* 0@p
44|
45* 1@p
46)
47  ;
48...>
49}
50
51
52@script:python depends on report@
53p << r2.p;
54fn << r2.fn;
55@@
56
57msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn
58coccilib.report.print_report(p[0], msg)
v5.14.15
 1// SPDX-License-Identifier: GPL-2.0
 2/// Return statements in functions returning bool should use
 3/// true/false instead of 1/0.
 4//
 5// Confidence: High
 6// Options: --no-includes --include-headers
 7
 8virtual patch
 9virtual report
10virtual context
11
12@r1 depends on patch@
13identifier fn;
14typedef bool;
15symbol false;
16symbol true;
17@@
18
19bool fn ( ... )
20{
21<...
22return
23(
24- 0
25+ false
26|
27- 1
28+ true
29)
30  ;
31...>
32}
33
34@r2 depends on report || context@
35identifier fn;
36position p;
37@@
38
39bool fn ( ... )
40{
41<...
42return
43(
44* 0@p
45|
46* 1@p
47)
48  ;
49...>
50}
51
52
53@script:python depends on report@
54p << r2.p;
55fn << r2.fn;
56@@
57
58msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn
59coccilib.report.print_report(p[0], msg)