1 // SPDX-License-Identifier: GPL-2.0-only
3 /// Check for code that could use struct_size().
6 // Author: Jacob Keller <jacob.e.keller@intel.com>
7 // Copyright: (C) 2023 Intel Corporation
8 // Options: --no-includes --include-headers
15 // the overflow Kunit tests have some code which intentionally does not use
16 // the macros, so we want to ignore this code when reporting potential
19 identifier f = overflow_size_helpers_test;
24 //----------------------------------------------------------
26 //----------------------------------------------------------
28 @depends on !overflow_tests && context@
33 * (sizeof(*E1) + (E2 * sizeof(*E1->m)))
36 //----------------------------------------------------------
38 //----------------------------------------------------------
40 @depends on !overflow_tests && patch@
45 - (sizeof(*E1) + (E2 * sizeof(*E1->m)))
46 + struct_size(E1, m, E2)
49 //----------------------------------------------------------
50 // For org and report mode
51 //----------------------------------------------------------
53 @r depends on !overflow_tests && (org || report)@
59 (sizeof(*E1)@p + (E2 * sizeof(*E1->m)))
62 @script:python depends on org@
66 coccilib.org.print_todo(p[0], "WARNING should use struct_size")
68 @script:python depends on report@
72 msg="WARNING: Use struct_size"
73 coccilib.report.print_report(p[0], msg)