diff --git a/src/pluto/alg_info.c b/src/pluto/alg_info.c index f486f15d55..3f56fb1184 100644 --- a/src/pluto/alg_info.c +++ b/src/pluto/alg_info.c @@ -225,7 +225,7 @@ __alg_info_esp_add (struct alg_info_esp *alg_info, int ealg_id, unsigned ek_bits unsigned cnt = alg_info->alg_info_cnt, i; /* check for overflows */ - passert(cnt < elemsof(alg_info->esp)); + passert(cnt < countof(alg_info->esp)); /* dont add duplicates */ for (i = 0; i < cnt; i++) @@ -366,7 +366,7 @@ __alg_info_ike_add (struct alg_info_ike *alg_info, int ealg_id, unsigned ek_bits unsigned i; /* check for overflows */ - passert(cnt < elemsof(alg_info->ike)); + passert(cnt < countof(alg_info->ike)); /* dont add duplicates */ for (i = 0;i < cnt; i++) @@ -410,7 +410,7 @@ static void alg_info_ike_add (struct alg_info *alg_info, int ealg_id, int ek_bits, int aalg_id, int ak_bits, int modp_id) { int i = 0; - int n_groups = elemsof(default_ike_groups); + int n_groups = countof(default_ike_groups); /* if specified modp_id avoid loop over default_ike_groups */ if (modp_id) diff --git a/src/pluto/constants.h b/src/pluto/constants.h index 1ea9d2a73f..9b6d3eb473 100644 --- a/src/pluto/constants.h +++ b/src/pluto/constants.h @@ -30,8 +30,6 @@ extern void init_constants(void); * Any changes here should be reflected there. */ -#define elemsof(array) (sizeof(array) / sizeof(*(array))) /* number of elements in an array */ - /* Many routines return only success or failure, but wish to describe * the failure in a message. We use the convention that they return * a NULL on success and a pointer to constant string on failure. diff --git a/src/pluto/crypto.c b/src/pluto/crypto.c index 9d9155baca..20e4d9ec81 100644 --- a/src/pluto/crypto.c +++ b/src/pluto/crypto.c @@ -510,7 +510,7 @@ lookup_group(u_int16_t group) { int i; - for (i = 0; i != elemsof(oakley_group); i++) + for (i = 0; i != countof(oakley_group); i++) if (group == oakley_group[i].group) return &oakley_group[i]; return NULL; diff --git a/src/pluto/demux.c b/src/pluto/demux.c index 32e527e400..7e2afac666 100644 --- a/src/pluto/demux.c +++ b/src/pluto/demux.c @@ -526,7 +526,7 @@ init_demux(void) */ const struct state_microcode *t; - for (t = &state_microcode_table[elemsof(state_microcode_table) - 1];;) + for (t = &state_microcode_table[countof(state_microcode_table) - 1];;) { passert(STATE_IKE_FLOOR <= t->state && t->state < STATE_IKE_ROOF); ike_microcode_index[t->state - STATE_IKE_FLOOR] = t; diff --git a/src/pluto/dnskey.c b/src/pluto/dnskey.c index 065f85d47a..d263273388 100644 --- a/src/pluto/dnskey.c +++ b/src/pluto/dnskey.c @@ -1117,7 +1117,7 @@ process_dns_answer(struct adns_continuation *const cr r = (qr_header.stuff >> QRS_RCODE_SHIFT) & QRS_RCODE_MASK; if (r != 0) - return r < (int)elemsof(rcode_text)? rcode_text[r] : "unknown rcode"; + return r < (int)countof(rcode_text)? rcode_text[r] : "unknown rcode"; if (qr_header.ancount == 0) return builddiag("no %s RR found by DNS", rr_typename(type)); diff --git a/src/pluto/ike_alg.c b/src/pluto/ike_alg.c index 5e34b272da..5d48dd45c9 100644 --- a/src/pluto/ike_alg.c +++ b/src/pluto/ike_alg.c @@ -378,7 +378,7 @@ ike_alg_list(void) whack_log(RC_COMMENT, "List of registered IKE DH Groups:"); whack_log(RC_COMMENT, " "); - for (i = 0; i < elemsof(oakley_group); i++) + for (i = 0; i < countof(oakley_group); i++) { const struct oakley_group_desc *gdesc=oakley_group + i; diff --git a/src/pluto/kernel.c b/src/pluto/kernel.c index 59a505733e..c830485d9e 100644 --- a/src/pluto/kernel.c +++ b/src/pluto/kernel.c @@ -1460,7 +1460,7 @@ scan_proc_shunts(void) * Note: if there are too many fields, just stop; * it will be diagnosed a little later. */ - for (fi = 0; fi < (int)elemsof(field); fi++) + for (fi = 0; fi < (int)countof(field); fi++) { static const char sep[] = " \t\n"; /* field-separating whitespace */ size_t w; @@ -1869,7 +1869,7 @@ setup_half_ipsec_sa(struct state *st, bool inbound) for (ei = esp_info; ; ei++) { - if (ei == &esp_info[elemsof(esp_info)]) + if (ei == &esp_info[countof(esp_info)]) { /* Check for additional kernel alg */ #ifndef NO_KERNEL_ALG diff --git a/src/pluto/keys.c b/src/pluto/keys.c index 89034d61b7..f9cbd5aa01 100644 --- a/src/pluto/keys.c +++ b/src/pluto/keys.c @@ -483,7 +483,7 @@ process_rsa_secret(RSA_private_key_t *rsak) MP_INT *n = (MP_INT *) ((char *)rsak + p->offset); n_to_mpz(n, buf, sz); - if (pb_next < &pub_bytes[elemsof(pub_bytes)]) + if (pb_next < &pub_bytes[countof(pub_bytes)]) { if (eb_next - ebytes + sz > sizeof(ebytes)) return "public key takes too many bytes"; diff --git a/src/pluto/pkcs1.c b/src/pluto/pkcs1.c index 6dcc0659c9..c444cc3366 100644 --- a/src/pluto/pkcs1.c +++ b/src/pluto/pkcs1.c @@ -134,7 +134,7 @@ RSA_show_key_fields(RSA_private_key_t *k, int fieldcnt) void RSA_show_private_key(RSA_private_key_t *k) { - RSA_show_key_fields(k, elemsof(RSA_private_field)); + RSA_show_key_fields(k, countof(RSA_private_field)); } void diff --git a/src/pluto/server.c b/src/pluto/server.c index 3b25292869..cc32ea82b4 100644 --- a/src/pluto/server.c +++ b/src/pluto/server.c @@ -212,7 +212,7 @@ static int pluto_ifn_roof = 0; bool use_interface(const char *rifn) { - if (pluto_ifn_roof >= (int)elemsof(pluto_ifn)) + if (pluto_ifn_roof >= (int)countof(pluto_ifn)) { return FALSE; } diff --git a/src/pluto/spdb.c b/src/pluto/spdb.c index 8699132daf..3f9133df29 100644 --- a/src/pluto/spdb.c +++ b/src/pluto/spdb.c @@ -45,7 +45,7 @@ #include "db_ops.h" #include "nat_traversal.h" -#define AD(x) x, elemsof(x) /* Array Description */ +#define AD(x) x, countof(x) /* Array Description */ #define AD_NULL NULL, 0 /**************** Oakely (main mode) SA database ****************/