dist/tools: add Coccinelle check for ARRAYSIZE
This Coccinelle script will warn when new code has the potential to use
the macro ARRAYSIZE instead of something like this
sizeof(some_array) / sizeof(some_array[0])
This commit is contained in:
parent
34b5d499d0
commit
c1d3128be3
58
dist/tools/coccinelle/warn/arraysize.cocci
vendored
Normal file
58
dist/tools/coccinelle/warn/arraysize.cocci
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// Use the macro ARRAY_SIZE when possible
|
||||||
|
//
|
||||||
|
// Confidence: High
|
||||||
|
// Copyright: (C) Gilles Muller, Julia Lawall, EMN, INRIA, DIKU. GPLv2.
|
||||||
|
// URL: http://coccinelle.lip6.fr/rules/array.html
|
||||||
|
// Options: -I ... -all_includes can give more complete results
|
||||||
|
|
||||||
|
// This is a modified version for RIOT-OS.
|
||||||
|
// At first it was used to help with Pull Request 11865
|
||||||
|
// Now it helps to warn when it is possible to use the macro
|
||||||
|
// in new code.
|
||||||
|
|
||||||
|
@@
|
||||||
|
type T;
|
||||||
|
T[] E;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- (sizeof(E)/sizeof(*E))
|
||||||
|
+ ARRAY_SIZE(E)
|
||||||
|
|
||||||
|
@@
|
||||||
|
type T;
|
||||||
|
T[] E;
|
||||||
|
T E2;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- (sizeof(E)/sizeof(E2))
|
||||||
|
+ ARRAY_SIZE(E)
|
||||||
|
|
||||||
|
@@
|
||||||
|
type T;
|
||||||
|
T[] E;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- (sizeof(E)/sizeof(E[...]))
|
||||||
|
+ ARRAY_SIZE(E)
|
||||||
|
|
||||||
|
@@
|
||||||
|
type T;
|
||||||
|
T[] E;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- (sizeof(E)/sizeof(T))
|
||||||
|
+ ARRAY_SIZE(E)
|
||||||
|
|
||||||
|
@n@
|
||||||
|
identifier AS,E;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- #define AS(E) ARRAY_SIZE(E)
|
||||||
|
|
||||||
|
@@
|
||||||
|
expression E;
|
||||||
|
identifier n.AS;
|
||||||
|
@@
|
||||||
|
|
||||||
|
- AS(E)
|
||||||
|
+ ARRAY_SIZE(E)
|
||||||
Loading…
x
Reference in New Issue
Block a user