From 0a4418cd4bb0cb3b9bbe730fb8b01a57ded2216e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 25 Jun 2013 08:55:46 -0400 Subject: [PATCH] consistent use of existing macros --- daemon/aux.h | 3 --- daemon/call.c | 10 +++++----- daemon/crypto.c | 4 ++-- daemon/rtcp.c | 3 ++- daemon/stun.c | 3 ++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/daemon/aux.h b/daemon/aux.h index d7b4a5520..90e3be4d6 100644 --- a/daemon/aux.h +++ b/daemon/aux.h @@ -21,9 +21,6 @@ #define OFFSET_OF(t,e) ((unsigned int) (unsigned long) &(((t *) 0)->e)) #define ZERO(x) memset(&(x), 0, sizeof(x)) -#ifndef ARRAYSIZE -#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a))) -#endif #define IPF "%u.%u.%u.%u" #define IPP(x) ((unsigned char *) (&(x)))[0], ((unsigned char *) (&(x)))[1], ((unsigned char *) (&(x)))[2], ((unsigned char *) (&(x)))[3] diff --git a/daemon/call.c b/daemon/call.c index c166fa7ce..9024d1837 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -1474,7 +1474,7 @@ void relays_cache_init(struct relays_cache *c) { } int relays_cache_want_ports(struct relays_cache *c, int portA, int portB, struct call *call) { - if (c->relays_open + 2 > ARRAYSIZE(c->relays_A)) + if (c->relays_open + 2 > G_N_ELEMENTS(c->relays_A)) return -1; if (get_consecutive_ports(&c->relays_A[c->relays_open], 2, portA, call)) return -1; @@ -1489,7 +1489,7 @@ static int relays_cache_get_ports(struct relays_cache *c, int num, struct call * if (c->relays_open >= num) return 0; - if (c->relays_open + num > ARRAYSIZE(c->relays_A)) + if (c->relays_open + num > G_N_ELEMENTS(c->relays_A)) return -1; if (get_consecutive_ports(&c->relays_A[c->relays_open], num, 0, call)) return -1; @@ -1517,12 +1517,12 @@ static void relays_cache_port_used(struct relays_cache *c) { void relays_cache_cleanup(struct relays_cache *c, struct callmaster *m) { int i; - for (i = 0; i < ARRAYSIZE(c->relays_A); i++) { + for (i = 0; i < G_N_ELEMENTS(c->relays_A); i++) { if (c->relays_A[i].fd == -1) break; release_port(&c->relays_A[i], m); } - for (i = 0; i < ARRAYSIZE(c->relays_B); i++) { + for (i = 0; i < G_N_ELEMENTS(c->relays_B); i++) { if (c->relays_B[i].fd == -1) break; release_port(&c->relays_B[i], m); @@ -1880,7 +1880,7 @@ static csa_func __call_stream_address(struct peer *p, int variant) { csa_func variants[2]; assert(variant >= 0); - assert(variant < ARRAYSIZE(variants)); + assert(variant < G_N_ELEMENTS(variants)); m = p->up->call->callmaster; other = p->other; diff --git a/daemon/crypto.c b/daemon/crypto.c index e3e5694ae..306fe12ac 100644 --- a/daemon/crypto.c +++ b/daemon/crypto.c @@ -103,7 +103,7 @@ const struct crypto_suite crypto_suites[] = { }, }; -const int num_crypto_suites = ARRAYSIZE(crypto_suites); +const int num_crypto_suites = G_N_ELEMENTS(crypto_suites); @@ -456,7 +456,7 @@ static int evp_session_key_cleanup(struct crypto_context *c) { unsigned char block[16]; int len, i; - for (i = 0; i < ARRAYSIZE(c->session_key_ctx); i++) { + for (i = 0; i < G_N_ELEMENTS(c->session_key_ctx); i++) { if (!c->session_key_ctx[i]) continue; diff --git a/daemon/rtcp.c b/daemon/rtcp.c index 921ee1f13..b540a9c53 100644 --- a/daemon/rtcp.c +++ b/daemon/rtcp.c @@ -3,6 +3,7 @@ #include #include #include +#include #include "str.h" #include "call.h" @@ -246,7 +247,7 @@ static int rtcp_parse(GQueue *q, str *_s) { if ((hdr->header.v_p_x & 0xc0) != 0x80) /* version 2 */ goto error; - if (hdr->header.pt >= ARRAYSIZE(handler_funcs)) + if (hdr->header.pt >= G_N_ELEMENTS(handler_funcs)) goto error; func = handler_funcs[hdr->header.pt]; if (!func) diff --git a/daemon/stun.c b/daemon/stun.c index 31942ed1f..54c32fe2f 100644 --- a/daemon/stun.c +++ b/daemon/stun.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "str.h" #include "aux.h" @@ -352,7 +353,7 @@ static int check_auth(str *msg, struct stun_attrs *attrs, struct peer *peer) { iov[2].iov_base = msg->s + OFFSET_OF(struct header, cookie); iov[2].iov_len = ntohs(lenX) + - 24 + 20 - OFFSET_OF(struct header, cookie); - __integrity(iov, ARRAYSIZE(iov), &peer->ice_pwd, digest); + __integrity(iov, G_N_ELEMENTS(iov), &peer->ice_pwd, digest); return memcmp(digest, attrs->msg_integrity.s, 20) ? -1 : 0; }