[PATCH 1/4] cocci: add script for zero-length arrays in structs
Bruce Richardson
bruce.richardson at intel.com
Thu Jun 2 17:08:31 CEST 2022
Add script to replace [0] with [] when used at the end of a struct.
The script also includes an additional struct member to match against so
as to avoid issues with arrays with only a single zero-length element.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
devtools/cocci/zero_length_array.cocci | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
create mode 100644 devtools/cocci/zero_length_array.cocci
diff --git a/devtools/cocci/zero_length_array.cocci b/devtools/cocci/zero_length_array.cocci
new file mode 100644
index 0000000000..de8783bc7a
--- /dev/null
+++ b/devtools/cocci/zero_length_array.cocci
@@ -0,0 +1,21 @@
+// Replace zero-length array members with []
+@@
+identifier st, member, arr;
+type T1, T2;
+@@
+struct st {
+ ...
+ T1 member;
+- T2 arr[0];
++ T2 arr[];
+};
+@@
+identifier st, member, arr, id;
+type T1, T2;
+@@
+struct st {
+ ...
+ T1 member;
+- T2 arr[0];
++ T2 arr[];
+} id;
--
2.34.1
More information about the dev
mailing list