Add a simple coccinelle patch for finding NELEM() candidates.
authorSascha Wildner <saw@online.de>
Sun, 4 Dec 2011 16:06:44 +0000 (17:06 +0100)
committerSascha Wildner <saw@online.de>
Sun, 4 Dec 2011 16:06:44 +0000 (17:06 +0100)
From a similar NetBSD patch from the web.

test/cocci/NELEM.cocci [new file with mode: 0644]

diff --git a/test/cocci/NELEM.cocci b/test/cocci/NELEM.cocci
new file mode 100644 (file)
index 0000000..7cf4429
--- /dev/null
@@ -0,0 +1,28 @@
+@param@
+@@
+
+#include <sys/param.h>
+
+@depends on param@
+type E;
+E[] T;
+@@
+
+- sizeof(T)/sizeof(E)
++ NELEM(T)
+
+@depends on param@
+type E;
+E[] T;
+@@
+
+- sizeof(T)/sizeof(*T)
++ NELEM(T)
+
+@depends on param@
+type E;
+E[] T;
+@@
+
+- sizeof(T)/sizeof(T[...])
++ NELEM(T)