Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /// sizeof when applied to a pointer typed expression gives the size of
0003 /// the pointer
0004 ///
0005 // Confidence: High
0006 // Copyright: (C) 2012 Julia Lawall, INRIA/LIP6.
0007 // Copyright: (C) 2012 Gilles Muller, INRIA/LiP6.
0008 // URL: https://coccinelle.gitlabpages.inria.fr/website
0009 // Comments:
0010 // Options: --no-includes --include-headers
0011 
0012 virtual org
0013 virtual report
0014 virtual context
0015 virtual patch
0016 
0017 @depends on patch@
0018 expression *x;
0019 expression f;
0020 expression i;
0021 type T;
0022 @@
0023 
0024 (
0025 x = <+... sizeof(
0026 - x
0027 + *x
0028    ) ...+>
0029 |
0030 f(...,(T)(x),...,sizeof(
0031 - x
0032 + *x
0033    ),...)
0034 |
0035 f(...,sizeof(
0036 - x
0037 + *x
0038    ),...,(T)(x),...)
0039 |
0040 f(...,(T)(x),...,i*sizeof(
0041 - x
0042 + *x
0043    ),...)
0044 |
0045 f(...,i*sizeof(
0046 - x
0047 + *x
0048    ),...,(T)(x),...)
0049 )
0050 
0051 @r depends on !patch@
0052 expression *x;
0053 expression f;
0054 expression i;
0055 position p;
0056 type T;
0057 @@
0058 
0059 (
0060 *x = <+... sizeof@p(x) ...+>
0061 |
0062 *f(...,(T)(x),...,sizeof@p(x),...)
0063 |
0064 *f(...,sizeof@p(x),...,(T)(x),...)
0065 |
0066 *f(...,(T)(x),...,i*sizeof@p(x),...)
0067 |
0068 *f(...,i*sizeof@p(x),...,(T)(x),...)
0069 )
0070 
0071 @script:python depends on org@
0072 p << r.p;
0073 @@
0074 
0075 cocci.print_main("application of sizeof to pointer",p)
0076 
0077 @script:python depends on report@
0078 p << r.p;
0079 @@
0080 
0081 msg = "ERROR: application of sizeof to pointer"
0082 coccilib.report.print_report(p[0],msg)