From 11bf11c1f55402cc08deeb53ee94387afc4a4525 Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Fri, 4 Jul 2014 14:37:58 +0200 Subject: [PATCH] utils: Check if the parameter passed to countof() is actually an array type This should avoid errors such as the one fixed with 118b2879. --- src/libstrongswan/utils/utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libstrongswan/utils/utils.h b/src/libstrongswan/utils/utils.h index cb60c6e3e2..da253cc357 100644 --- a/src/libstrongswan/utils/utils.h +++ b/src/libstrongswan/utils/utils.h @@ -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 -- 2.47.2