noderef.cocci 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /// sizeof when applied to a pointer typed expression gives the size of
  3. /// the pointer
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
  7. // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
  8. // URL: https://coccinelle.gitlabpages.inria.fr/website
  9. // Comments:
  10. // Options: --no-includes --include-headers
  11. virtual org
  12. virtual report
  13. virtual context
  14. virtual patch
  15. @depends on patch@
  16. expression *x;
  17. expression f;
  18. expression i;
  19. type T;
  20. @@
  21. (
  22. x = <+... sizeof(
  23. - x
  24. + *x
  25. ) ...+>
  26. |
  27. f(...,(T)(x),...,sizeof(
  28. - x
  29. + *x
  30. ),...)
  31. |
  32. f(...,sizeof(
  33. - x
  34. + *x
  35. ),...,(T)(x),...)
  36. |
  37. f(...,(T)(x),...,i*sizeof(
  38. - x
  39. + *x
  40. ),...)
  41. |
  42. f(...,i*sizeof(
  43. - x
  44. + *x
  45. ),...,(T)(x),...)
  46. )
  47. @r depends on !patch@
  48. expression *x;
  49. expression f;
  50. expression i;
  51. position p;
  52. type T;
  53. @@
  54. (
  55. *x = <+... sizeof@p(x) ...+>
  56. |
  57. *f(...,(T)(x),...,sizeof@p(x),...)
  58. |
  59. *f(...,sizeof@p(x),...,(T)(x),...)
  60. |
  61. *f(...,(T)(x),...,i*sizeof@p(x),...)
  62. |
  63. *f(...,i*sizeof@p(x),...,(T)(x),...)
  64. )
  65. @script:python depends on org@
  66. p << r.p;
  67. @@
  68. cocci.print_main("application of sizeof to pointer",p)
  69. @script:python depends on report@
  70. p << r.p;
  71. @@
  72. msg = "ERROR: application of sizeof to pointer"
  73. coccilib.report.print_report(p[0],msg)