resource_size.cocci 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ///
  2. /// Use resource_size function on resource object
  3. /// instead of explicit computation.
  4. ///
  5. // Confidence: High
  6. // Copyright: (C) 2009, 2010 Nicolas Palix, DIKU. GPLv2.
  7. // Copyright: (C) 2009, 2010 Julia Lawall, DIKU. GPLv2.
  8. // Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6. GPLv2.
  9. // URL: http://coccinelle.lip6.fr/
  10. // Options:
  11. //
  12. // Keywords: resource_size
  13. // Version min: 2.6.27 resource_size
  14. //
  15. virtual context
  16. virtual patch
  17. virtual org
  18. virtual report
  19. //----------------------------------------------------------
  20. // For context mode
  21. //----------------------------------------------------------
  22. @r_context depends on context && !patch && !org@
  23. struct resource *res;
  24. @@
  25. * (res->end - res->start) + 1
  26. //----------------------------------------------------------
  27. // For patch mode
  28. //----------------------------------------------------------
  29. @r_patch depends on !context && patch && !org@
  30. struct resource *res;
  31. @@
  32. - (res->end - res->start) + 1
  33. + resource_size(res)
  34. //----------------------------------------------------------
  35. // For org mode
  36. //----------------------------------------------------------
  37. @r_org depends on !context && !patch && (org || report)@
  38. struct resource *res;
  39. position p;
  40. @@
  41. (res->end@p - res->start) + 1
  42. @rbad_org depends on !context && !patch && (org || report)@
  43. struct resource *res;
  44. position p != r_org.p;
  45. @@
  46. res->end@p - res->start
  47. @script:python depends on org@
  48. p << r_org.p;
  49. x << r_org.res;
  50. @@
  51. msg="ERROR with %s" % (x)
  52. msg_safe=msg.replace("[","@(").replace("]",")")
  53. coccilib.org.print_todo(p[0], msg_safe)
  54. @script:python depends on report@
  55. p << r_org.p;
  56. x << r_org.res;
  57. @@
  58. msg="ERROR: Missing resource_size with %s" % (x)
  59. coccilib.report.print_report(p[0], msg)
  60. @script:python depends on org@
  61. p << rbad_org.p;
  62. x << rbad_org.res;
  63. @@
  64. msg="WARNING with %s" % (x)
  65. msg_safe=msg.replace("[","@(").replace("]",")")
  66. coccilib.org.print_todo(p[0], msg_safe)
  67. @script:python depends on report@
  68. p << rbad_org.p;
  69. x << rbad_org.res;
  70. @@
  71. msg="WARNING: Suspicious code. resource_size is maybe missing with %s" % (x)
  72. coccilib.report.print_report(p[0], msg)