doubletest.cocci 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// Find &&/|| operations that include the same argument more than once
  3. //# A common source of false positives is when the expression, or
  4. //# another expresssion in the same && or || operation, performs a
  5. //# side effect.
  6. ///
  7. // Confidence: Moderate
  8. // Copyright: (C) 2010 Nicolas Palix, DIKU.
  9. // Copyright: (C) 2010 Julia Lawall, DIKU.
  10. // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
  11. // URL: https://coccinelle.gitlabpages.inria.fr/website
  12. // Comments:
  13. // Options: --no-includes --include-headers
  14. virtual context
  15. virtual org
  16. virtual report
  17. @r expression@
  18. expression E;
  19. position p;
  20. @@
  21. (
  22. E@p || ... || E
  23. |
  24. E@p && ... && E
  25. )
  26. @bad@
  27. expression r.E,e1,e2,fn;
  28. position r.p;
  29. assignment operator op;
  30. @@
  31. (
  32. E@p
  33. &
  34. <+... \(fn(...)\|e1 op e2\|e1++\|e1--\|++e1\|--e1\) ...+>
  35. )
  36. @depends on context && !bad@
  37. expression r.E;
  38. position r.p;
  39. @@
  40. *E@p
  41. @script:python depends on org && !bad@
  42. p << r.p;
  43. @@
  44. cocci.print_main("duplicated argument to && or ||",p)
  45. @script:python depends on report && !bad@
  46. p << r.p;
  47. @@
  48. coccilib.report.print_report(p[0],"duplicated argument to && or ||")