boolreturn.cocci 662 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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)