diff options
| author | Rasmus Villemoes <linux@rasmusvillemoes.dk> | 2013-08-11 17:05:12 -0400 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2013-08-13 16:43:41 -0400 |
| commit | 46b5c9b856e8bcb44d8570cc55c46d19ca2428ff (patch) | |
| tree | 32f76c8658a3c855d48f9313f98a2636df9c67f9 /scripts | |
| parent | c95182bf9bd2df55739b187df8e972cb6cbee895 (diff) | |
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')
| -rw-r--r-- | scripts/coccinelle/misc/boolreturn.cocci | 58 |
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 @@ | |||
| 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 | |||
| 7 | virtual patch | ||
| 8 | virtual report | ||
| 9 | virtual context | ||
| 10 | |||
| 11 | @r1 depends on patch@ | ||
| 12 | identifier fn; | ||
| 13 | typedef bool; | ||
| 14 | symbol false; | ||
| 15 | symbol true; | ||
| 16 | @@ | ||
| 17 | |||
| 18 | bool fn ( ... ) | ||
| 19 | { | ||
| 20 | <... | ||
| 21 | return | ||
| 22 | ( | ||
| 23 | - 0 | ||
| 24 | + false | ||
| 25 | | | ||
| 26 | - 1 | ||
| 27 | + true | ||
| 28 | ) | ||
| 29 | ; | ||
| 30 | ...> | ||
| 31 | } | ||
| 32 | |||
| 33 | @r2 depends on report || context@ | ||
| 34 | identifier fn; | ||
| 35 | position p; | ||
| 36 | @@ | ||
| 37 | |||
| 38 | bool fn ( ... ) | ||
| 39 | { | ||
| 40 | <... | ||
| 41 | return | ||
| 42 | ( | ||
| 43 | * 0@p | ||
| 44 | | | ||
| 45 | * 1@p | ||
| 46 | ) | ||
| 47 | ; | ||
| 48 | ...> | ||
| 49 | } | ||
| 50 | |||
| 51 | |||
| 52 | @script:python depends on report@ | ||
| 53 | p << r2.p; | ||
| 54 | fn << r2.fn; | ||
| 55 | @@ | ||
| 56 | |||
| 57 | msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn | ||
| 58 | coccilib.report.print_report(p[0], msg) | ||
