1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples: make use of ARRAY_SIZE macro

This commit is contained in:
Benjamin Valentin 2019-07-18 15:18:32 +02:00
parent 9d6d93ef2f
commit d16afe5422
7 changed files with 8 additions and 8 deletions

View File

@ -83,7 +83,7 @@ static const coap_resource_t _resources[] = {
static gcoap_listener_t _listener = {
.resources = (coap_resource_t *)&_resources[0],
.resources_len = sizeof(_resources) / sizeof(_resources[0]),
.resources_len = ARRAY_SIZE(_resources),
.next = NULL
};

View File

@ -61,7 +61,7 @@ static const coap_resource_t resources[] = {
static gcoap_listener_t listener = {
.resources = &resources[0],
.resources_len = sizeof(resources) / sizeof(resources[0]),
.resources_len = ARRAY_SIZE(resources),
.next = NULL
};

View File

@ -210,7 +210,7 @@ static int _peer_get_psk_info_handler(struct dtls_context_t *ctx, const session_
if (id) {
uint8_t i;
for (i = 0; i < sizeof(psk) / sizeof(struct keymap_t); i++) {
for (i = 0; i < ARRAY_SIZE(psk); i++) {
if (id_len == psk[i].id_length && memcmp(id, psk[i].id, id_len) == 0) {
if (result_length < psk[i].key_length) {
dtls_warn("buffer too small for PSK");

View File

@ -265,7 +265,7 @@ int main(void)
"information.");
/* the main thread needs a msg queue to be able to run `ping6`*/
msg_init_queue(queue, (sizeof(queue) / sizeof(msg_t)));
msg_init_queue(queue, ARRAY_SIZE(queue));
/* initialize our subscription buffers */
memset(subscriptions, 0, (NUMOFSUBS * sizeof(emcute_sub_t)));

View File

@ -98,7 +98,7 @@ static constfs_file_t constfs_files[] = {
/* this is the constfs specific descriptor */
static constfs_t constfs_desc = {
.nfiles = sizeof(constfs_files) / sizeof(constfs_files[0]),
.nfiles = ARRAY_SIZE(constfs_files),
.files = constfs_files,
};

View File

@ -49,7 +49,7 @@ static const char *_link_params[] = {
static gcoap_listener_t _listener = {
&_resources[0],
sizeof(_resources) / sizeof(_resources[0]),
ARRAY_SIZE(_resources),
_encode_link,
NULL
};
@ -253,7 +253,7 @@ int gcoap_cli_cmd(int argc, char **argv)
/* if not 'info', must be a method code */
int code_pos = -1;
for (size_t i = 0; i < sizeof(method_codes) / sizeof(char*); i++) {
for (size_t i = 0; i < ARRAY_SIZE(method_codes); i++) {
if (strcmp(argv[1], method_codes[i]) == 0) {
code_pos = i;
}

View File

@ -169,4 +169,4 @@ const coap_resource_t coap_resources[] = {
{ "/sha256", COAP_POST, _sha256_handler, NULL },
};
const unsigned coap_resources_numof = sizeof(coap_resources) / sizeof(coap_resources[0]);
const unsigned coap_resources_numof = ARRAY_SIZE(coap_resources);