From 66117601bbcc19a9b95c65f79facf44edf043961 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 18 Jul 2019 15:20:42 +0200 Subject: [PATCH] pkg: make use of ARRAY_SIZE macro --- pkg/lua/contrib/lua_loadlib.c | 3 ++- pkg/lua/contrib/lua_run.c | 2 +- pkg/lwip/contrib/lwip.c | 6 +++--- pkg/nimble/scanlist/nimble_scanlist.c | 2 +- pkg/nordic_softdevice_ble/src/ble-core.c | 2 +- pkg/openthread/contrib/openthread.c | 2 +- pkg/openthread/contrib/platform_functions_wrapper.c | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/lua/contrib/lua_loadlib.c b/pkg/lua/contrib/lua_loadlib.c index b746044a52..8e9e6a7cf8 100644 --- a/pkg/lua/contrib/lua_loadlib.c +++ b/pkg/lua/contrib/lua_loadlib.c @@ -30,6 +30,7 @@ #define LUA_LIB #include "lprefix.h" +#include "kernel_defines.h" #include "lua.h" #include "lauxlib.h" @@ -239,7 +240,7 @@ LUAMOD_API int luaopen_package(lua_State *L) luaL_newlib(L, pk_funcs); /* create 'package' table */ /* create 'searchers' table */ - lua_createtable(L, sizeof(searchers) / sizeof(searchers[0]) - 1, 0); + lua_createtable(L, ARRAY_SIZE(searchers) - 1, 0); /* fill it with predefined searchers */ for (i = 0; searchers[i] != NULL; i++) { lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */ diff --git a/pkg/lua/contrib/lua_run.c b/pkg/lua/contrib/lua_run.c index fcb57f1689..e6fa84f9d8 100644 --- a/pkg/lua/contrib/lua_run.c +++ b/pkg/lua/contrib/lua_run.c @@ -272,7 +272,7 @@ LUALIB_API int lua_riot_do_buffer(const uint8_t *buf, size_t buflen, void *memor modmask, retval); } -#define MAX_ERR_STRING ((sizeof(lua_riot_str_errors) / sizeof(*lua_riot_str_errors)) - 1) +#define MAX_ERR_STRING (ARRAY_SIZE(lua_riot_str_errors) - 1) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) LUALIB_API const char *lua_riot_strerror(int errn) diff --git a/pkg/lwip/contrib/lwip.c b/pkg/lwip/contrib/lwip.c index 9c738801f3..8cb0aca709 100644 --- a/pkg/lwip/contrib/lwip.c +++ b/pkg/lwip/contrib/lwip.c @@ -48,15 +48,15 @@ #endif #ifdef MODULE_AT86RF2XX /* is mutual exclusive with above ifdef */ -#define LWIP_NETIF_NUMOF (sizeof(at86rf2xx_params) / sizeof(at86rf2xx_params[0])) +#define LWIP_NETIF_NUMOF ARRAY_SIZE(at86rf2xx_params) #endif #ifdef MODULE_MRF24J40 /* is mutual exclusive with above ifdef */ -#define LWIP_NETIF_NUMOF (sizeof(mrf24j40_params) / sizeof(mrf24j40_params[0])) +#define LWIP_NETIF_NUMOF ARRAY_SIZE(mrf24j40_params) #endif #ifdef MODULE_SOCKET_ZEP /* is mutual exclusive with above ifdef */ -#define LWIP_NETIF_NUMOF (sizeof(socket_zep_params) / sizeof(socket_zep_params[0])) +#define LWIP_NETIF_NUMOF ARRAY_SIZE(socket_zep_params) #endif #ifdef LWIP_NETIF_NUMOF diff --git a/pkg/nimble/scanlist/nimble_scanlist.c b/pkg/nimble/scanlist/nimble_scanlist.c index ad349a880a..6c364b1a20 100644 --- a/pkg/nimble/scanlist/nimble_scanlist.c +++ b/pkg/nimble/scanlist/nimble_scanlist.c @@ -50,7 +50,7 @@ static nimble_scanlist_entry_t *_find(const ble_addr_t *addr) void nimble_scanlist_init(void) { - for (unsigned i = 0; i < (sizeof(_mem) / sizeof(_mem[0])); i++) { + for (unsigned i = 0; i < ARRAY_SIZE(_mem); i++) { clist_rpush(&_pool, &_mem[i].node); } } diff --git a/pkg/nordic_softdevice_ble/src/ble-core.c b/pkg/nordic_softdevice_ble/src/ble-core.c index cd3c8c9f9c..361aa8015e 100644 --- a/pkg/nordic_softdevice_ble/src/ble-core.c +++ b/pkg/nordic_softdevice_ble/src/ble-core.c @@ -149,7 +149,7 @@ ble_advertising_init(const char *name) advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.flags = flags; - advdata.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]); + advdata.uuids_complete.uuid_cnt = ARRAY_SIZE(adv_uuids); advdata.uuids_complete.p_uuids = adv_uuids; err_code = ble_advdata_set(&advdata, NULL); diff --git a/pkg/openthread/contrib/openthread.c b/pkg/openthread/contrib/openthread.c index d9584b3a11..ab1028da30 100644 --- a/pkg/openthread/contrib/openthread.c +++ b/pkg/openthread/contrib/openthread.c @@ -34,7 +34,7 @@ #include "debug.h" #ifdef MODULE_AT86RF2XX /* is mutual exclusive with above ifdef */ -#define OPENTHREAD_NETIF_NUMOF (sizeof(at86rf2xx_params) / sizeof(at86rf2xx_params[0])) +#define OPENTHREAD_NETIF_NUMOF ARRAY_SIZE(at86rf2xx_params) #endif #ifdef MODULE_AT86RF2XX diff --git a/pkg/openthread/contrib/platform_functions_wrapper.c b/pkg/openthread/contrib/platform_functions_wrapper.c index 8693f70d17..2805163593 100644 --- a/pkg/openthread/contrib/platform_functions_wrapper.c +++ b/pkg/openthread/contrib/platform_functions_wrapper.c @@ -81,7 +81,7 @@ uint8_t ot_exec_command(otInstance *ot_instance, const char* command, void *arg, uint8_t res = 0xFF; /* Check running thread */ if (openthread_get_pid() == thread_getpid()) { - for (uint8_t i = 0; i < sizeof(otCommands) / sizeof(otCommands[0]); i++) { + for (uint8_t i = 0; i < ARRAY_SIZE(otCommands); i++) { if (strcmp(command, otCommands[i].name) == 0) { res = (*otCommands[i].function)(ot_instance, arg, answer); break;