0001 // SPDX-License-Identifier: GPL-2.0-only
0002 ///
0003 /// Use resource_size function on resource object
0004 /// instead of explicit computation.
0005 ///
0006 // Confidence: High
0007 // Copyright: (C) 2009, 2010 Nicolas Palix, DIKU.
0008 // Copyright: (C) 2009, 2010 Julia Lawall, DIKU.
0009 // Copyright: (C) 2009, 2010 Gilles Muller, INRIA/LiP6.
0010 // URL: https://coccinelle.gitlabpages.inria.fr/website
0011 // Options:
0012 //
0013 // Keywords: resource_size
0014 // Version min: 2.6.27 resource_size
0015 //
0016
0017 virtual context
0018 virtual patch
0019 virtual org
0020 virtual report
0021
0022 //----------------------------------------------------------
0023 // For context mode
0024 //----------------------------------------------------------
0025
0026 @r_context depends on context && !patch && !org@
0027 struct resource *res;
0028 @@
0029
0030 * (res->end - res->start) + 1
0031
0032 //----------------------------------------------------------
0033 // For patch mode
0034 //----------------------------------------------------------
0035
0036 @r_patch depends on !context && patch && !org@
0037 struct resource *res;
0038 @@
0039
0040 - (res->end - res->start) + 1
0041 + resource_size(res)
0042
0043 //----------------------------------------------------------
0044 // For org mode
0045 //----------------------------------------------------------
0046
0047
0048 @r_org depends on !context && !patch && (org || report)@
0049 struct resource *res;
0050 position p;
0051 @@
0052
0053 (res->end@p - res->start) + 1
0054
0055 @rbad_org depends on !context && !patch && (org || report)@
0056 struct resource *res;
0057 position p != r_org.p;
0058 @@
0059
0060 res->end@p - res->start
0061
0062 @script:python depends on org@
0063 p << r_org.p;
0064 x << r_org.res;
0065 @@
0066
0067 msg="ERROR with %s" % (x)
0068 msg_safe=msg.replace("[","@(").replace("]",")")
0069 coccilib.org.print_todo(p[0], msg_safe)
0070
0071 @script:python depends on report@
0072 p << r_org.p;
0073 x << r_org.res;
0074 @@
0075
0076 msg="ERROR: Missing resource_size with %s" % (x)
0077 coccilib.report.print_report(p[0], msg)
0078
0079 @script:python depends on org@
0080 p << rbad_org.p;
0081 x << rbad_org.res;
0082 @@
0083
0084 msg="WARNING with %s" % (x)
0085 msg_safe=msg.replace("[","@(").replace("]",")")
0086 coccilib.org.print_todo(p[0], msg_safe)
0087
0088 @script:python depends on report@
0089 p << rbad_org.p;
0090 x << rbad_org.res;
0091 @@
0092
0093 msg="WARNING: Suspicious code. resource_size is maybe missing with %s" % (x)
0094 coccilib.report.print_report(p[0], msg)