File: struct_size.cocci

package info (click to toggle)
linux 6.16.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,724,576 kB
  • sloc: ansic: 26,558,545; asm: 271,315; sh: 143,998; python: 72,469; makefile: 57,126; perl: 36,821; xml: 19,553; cpp: 5,820; yacc: 4,915; lex: 2,955; awk: 1,667; sed: 28; ruby: 25
file content (74 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: GPL-2.0-only
///
/// Check for code that could use struct_size().
///
// Confidence: Medium
// Author: Jacob Keller <jacob.e.keller@intel.com>
// Copyright: (C) 2023 Intel Corporation
// Options: --no-includes --include-headers

virtual patch
virtual context
virtual org
virtual report

// the overflow Kunit tests have some code which intentionally does not use
// the macros, so we want to ignore this code when reporting potential
// issues.
@overflow_tests@
identifier f = overflow_size_helpers_test;
@@

f

//----------------------------------------------------------
//  For context mode
//----------------------------------------------------------

@depends on !overflow_tests && context@
expression E1, E2;
identifier m;
@@
(
* (sizeof(*E1) + (E2 * sizeof(*E1->m)))
)

//----------------------------------------------------------
//  For patch mode
//----------------------------------------------------------

@depends on !overflow_tests && patch@
expression E1, E2;
identifier m;
@@
(
- (sizeof(*E1) + (E2 * sizeof(*E1->m)))
+ struct_size(E1, m, E2)
)

//----------------------------------------------------------
//  For org and report mode
//----------------------------------------------------------

@r depends on !overflow_tests && (org || report)@
expression E1, E2;
identifier m;
position p;
@@
(
 (sizeof(*E1)@p + (E2 * sizeof(*E1->m)))
)

@script:python depends on org@
p << r.p;
@@

coccilib.org.print_todo(p[0], "WARNING should use struct_size")

@script:python depends on report@
p << r.p;
@@

msg="WARNING: Use struct_size"
coccilib.report.print_report(p[0], msg)