itnull.cocci 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /// Many iterators have the property that the first argument is always bound
  2. /// to a real list element, never NULL. False positives arise for some
  3. /// iterators that do not have this property, or in cases when the loop
  4. /// cursor is reassigned. The latter should only happen when the matched
  5. /// code is on the way to a loop exit (break, goto, or return).
  6. ///
  7. // Confidence: Moderate
  8. // Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2.
  9. // Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2.
  10. // Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  11. // URL: http://coccinelle.lip6.fr/
  12. // Comments:
  13. // Options: -no_includes -include_headers
  14. virtual patch
  15. @@
  16. iterator I;
  17. expression x,E,E1,E2;
  18. statement S,S1,S2;
  19. @@
  20. I(x,...) { <...
  21. (
  22. - if (x == NULL && ...) S
  23. |
  24. - if (x != NULL || ...)
  25. S
  26. |
  27. - (x == NULL) ||
  28. E
  29. |
  30. - (x != NULL) &&
  31. E
  32. |
  33. - (x == NULL && ...) ? E1 :
  34. E2
  35. |
  36. - (x != NULL || ...) ?
  37. E1
  38. - : E2
  39. |
  40. - if (x == NULL && ...) S1 else
  41. S2
  42. |
  43. - if (x != NULL || ...)
  44. S1
  45. - else S2
  46. |
  47. + BAD(
  48. x == NULL
  49. + )
  50. |
  51. + BAD(
  52. x != NULL
  53. + )
  54. )
  55. ...> }