boolreturn.cocci 662 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. virtual patch
  7. virtual report
  8. virtual context
  9. @r1 depends on patch@
  10. identifier fn;
  11. typedef bool;
  12. symbol false;
  13. symbol true;
  14. @@
  15. bool fn ( ... )
  16. {
  17. <...
  18. return
  19. (
  20. - 0
  21. + false
  22. |
  23. - 1
  24. + true
  25. )
  26. ;
  27. ...>
  28. }
  29. @r2 depends on report || context@
  30. identifier fn;
  31. position p;
  32. @@
  33. bool fn ( ... )
  34. {
  35. <...
  36. return
  37. (
  38. * 0@p
  39. |
  40. * 1@p
  41. )
  42. ;
  43. ...>
  44. }
  45. @script:python depends on report@
  46. p << r2.p;
  47. fn << r2.fn;
  48. @@
  49. msg = "WARNING: return of 0/1 in function '%s' with return type bool" % fn
  50. coccilib.report.print_report(p[0], msg)