From: Martin Willi Date: Fri, 4 Jul 2014 12:37:58 +0000 (+0200) Subject: utils: Check if the parameter passed to countof() is actually an array type X-Git-Tag: 5.2.1dr1~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11bf11c1f55402cc08deeb53ee94387afc4a4525;p=thirdparty%2Fstrongswan.git utils: Check if the parameter passed to countof() is actually an array type This should avoid errors such as the one fixed with 118b2879. --- 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