summaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2013-08-11 21:05:12 +0000
committerMichal Marek <mmarek@suse.cz>2013-08-13 22:43:41 +0200
commit46b5c9b856e8bcb44d8570cc55c46d19ca2428ff (patch)
tree32f76c8658a3c855d48f9313f98a2636df9c67f9 /scripts/coccinelle
parentc95182bf9bd2df55739b187df8e972cb6cbee895 (diff)
downloadlinux-46b5c9b856e8bcb44d8570cc55c46d19ca2428ff.tar.bz2
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>
Diffstat (limited to 'scripts/coccinelle')
-rw-r--r--scripts/coccinelle/misc/boolreturn.cocci58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/coccinelle/misc/boolreturn.cocci b/scripts/coccinelle/misc/boolreturn.cocci
new file mode 100644
index 000000000000..a43c7b0c36ef
--- /dev/null
+++ b/scripts/coccinelle/misc/boolreturn.cocci
@@ -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)