[RFC,1/2] devtools: add script to check for zero length array

Message ID 20220215230058.64760-2-stephen@networkplumber.org (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers
Series Eliminate zero length arrays in DPDK |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 15, 2022, 11 p.m. UTC
  Use the same script as Linux kernel to find and replace
zero length arrays at end of structures.

Flexible arrays were introduced in C99 and help catch
some obvious errors (like incorrect sizeof).

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 devtools/cocci/zerolengtharray.cocci | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 devtools/cocci/zerolengtharray.cocci
  

Patch

diff --git a/devtools/cocci/zerolengtharray.cocci b/devtools/cocci/zerolengtharray.cocci
new file mode 100644
index 000000000000..50d8b00716ae
--- /dev/null
+++ b/devtools/cocci/zerolengtharray.cocci
@@ -0,0 +1,17 @@ 
+//
+// Replace all older style of one-element or zero length arrays
+// with current flexible member arraya
+//
+
+@@
+identifier S, member, array;
+type T1, T2;
+@@
+
+struct S {
+  ...
+  T1 member;
+  T2 array[
+- 0
+  ];
+};