pkg: make use of ARRAY_SIZE macro

This commit is contained in:
Benjamin Valentin 2019-07-18 15:20:42 +02:00
parent b8c4ab5b69
commit 66117601bb
7 changed files with 10 additions and 9 deletions

View File

@ -30,6 +30,7 @@
#define LUA_LIB #define LUA_LIB
#include "lprefix.h" #include "lprefix.h"
#include "kernel_defines.h"
#include "lua.h" #include "lua.h"
#include "lauxlib.h" #include "lauxlib.h"
@ -239,7 +240,7 @@ LUAMOD_API int luaopen_package(lua_State *L)
luaL_newlib(L, pk_funcs); /* create 'package' table */ luaL_newlib(L, pk_funcs); /* create 'package' table */
/* create 'searchers' 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 */ /* fill it with predefined searchers */
for (i = 0; searchers[i] != NULL; i++) { for (i = 0; searchers[i] != NULL; i++) {
lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */ lua_pushvalue(L, -2); /* set 'package' as upvalue for all searchers */

View File

@ -272,7 +272,7 @@ LUALIB_API int lua_riot_do_buffer(const uint8_t *buf, size_t buflen, void *memor
modmask, retval); 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)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
LUALIB_API const char *lua_riot_strerror(int errn) LUALIB_API const char *lua_riot_strerror(int errn)

View File

@ -48,15 +48,15 @@
#endif #endif
#ifdef MODULE_AT86RF2XX /* is mutual exclusive with above ifdef */ #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 #endif
#ifdef MODULE_MRF24J40 /* is mutual exclusive with above ifdef */ #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 #endif
#ifdef MODULE_SOCKET_ZEP /* is mutual exclusive with above ifdef */ #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 #endif
#ifdef LWIP_NETIF_NUMOF #ifdef LWIP_NETIF_NUMOF

View File

@ -50,7 +50,7 @@ static nimble_scanlist_entry_t *_find(const ble_addr_t *addr)
void nimble_scanlist_init(void) 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); clist_rpush(&_pool, &_mem[i].node);
} }
} }

View File

@ -149,7 +149,7 @@ ble_advertising_init(const char *name)
advdata.name_type = BLE_ADVDATA_FULL_NAME; advdata.name_type = BLE_ADVDATA_FULL_NAME;
advdata.flags = flags; 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; advdata.uuids_complete.p_uuids = adv_uuids;
err_code = ble_advdata_set(&advdata, NULL); err_code = ble_advdata_set(&advdata, NULL);

View File

@ -34,7 +34,7 @@
#include "debug.h" #include "debug.h"
#ifdef MODULE_AT86RF2XX /* is mutual exclusive with above ifdef */ #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 #endif
#ifdef MODULE_AT86RF2XX #ifdef MODULE_AT86RF2XX

View File

@ -81,7 +81,7 @@ uint8_t ot_exec_command(otInstance *ot_instance, const char* command, void *arg,
uint8_t res = 0xFF; uint8_t res = 0xFF;
/* Check running thread */ /* Check running thread */
if (openthread_get_pid() == thread_getpid()) { 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) { if (strcmp(command, otCommands[i].name) == 0) {
res = (*otCommands[i].function)(ot_instance, arg, answer); res = (*otCommands[i].function)(ot_instance, arg, answer);
break; break;