utils: Check if the parameter passed to countof() is actually an array type

This should avoid errors such as the one fixed with 118b2879.
This commit is contained in:
Martin Willi
2014-08-25 09:48:53 +02:00
parent bb6be26197
commit 11bf11c1f5
+2 -1
View File
@@ -356,7 +356,8 @@ static inline void *memset_noop(void *s, int c, size_t n)
/**
* Get the number of elements in an array
*/
#define countof(array) (sizeof(array)/sizeof(array[0]))
#define countof(array) (sizeof(array)/sizeof((array)[0]) \
+ BUILD_ASSERT_ARRAY(array))
/**
* Ignore result of functions tagged with warn_unused_result attributes