mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2025-04-14 11:17:33 +07:00
coccinelle: replace 0/1 with false/true in functions returning bool
This semantic patch replaces "return {0,1};" with "return {false,true};" in functions returning bool. Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Acked-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Michal Marek <mmarek@suse.cz>
This commit is contained in:
parent
c95182bf9b
commit
46b5c9b856
58
scripts/coccinelle/misc/boolreturn.cocci
Normal file
58
scripts/coccinelle/misc/boolreturn.cocci
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/// 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)
|
Loading…
Reference in New Issue
Block a user