cocci: add script for zero-length arrays in structs
authorBruce Richardson <bruce.richardson@intel.com>
Fri, 3 Jun 2022 11:16:22 +0000 (12:16 +0100)
committerDavid Marchand <david.marchand@redhat.com>
Tue, 7 Jun 2022 14:44:21 +0000 (16:44 +0200)
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@intel.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>
devtools/cocci/zero_length_array.cocci [new file with mode: 0644]

diff --git a/devtools/cocci/zero_length_array.cocci b/devtools/cocci/zero_length_array.cocci
new file mode 100644 (file)
index 0000000..de8783b
--- /dev/null
@@ -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;