From b6eb9827a6866981c08cc9613ca8b4a648894fb1 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sat, 2 May 2015 18:30:00 +0100 Subject: Add OSSL_NELEM macro. Add OSSL_NELEM macro to e_os.h to determine the number of elements in an array. Reviewed-by: Tim Hudson --- crypto/asn1/a_strnid.c | 10 +++------- crypto/asn1/ameth_lib.c | 10 ++++------ crypto/asn1/asn1_gen.c | 2 +- crypto/bio/bss_file.c | 2 +- crypto/bn/bn_dh.c | 5 +++-- crypto/bn/bn_gf2m.c | 4 ++-- crypto/bn/bn_nist.c | 20 ++++++++++---------- crypto/bn/bn_srp.c | 29 +++++++++++++++-------------- crypto/ec/ec_curve.c | 7 ++++--- crypto/evp/evp_pbe.c | 5 ++--- crypto/objects/obj_xref.c | 12 +++++------- crypto/rand/rand_unix.c | 5 ++--- crypto/ts/ts_rsp_print.c | 3 +-- crypto/ts/ts_rsp_verify.c | 2 +- crypto/x509/x509_trs.c | 2 +- crypto/x509/x509_vpm.c | 8 +++----- crypto/x509v3/tabtest.c | 2 +- crypto/x509v3/v3_purp.c | 5 ++--- 18 files changed, 61 insertions(+), 72 deletions(-) (limited to 'crypto') diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index 213cf63e59..5126298673 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -220,9 +220,7 @@ ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) if (idx >= 0) return sk_ASN1_STRING_TABLE_value(stable, idx); } - return OBJ_bsearch_table(&fnd, tbl_standard, - sizeof(tbl_standard) / - sizeof(ASN1_STRING_TABLE)); + return OBJ_bsearch_table(&fnd, tbl_standard, OSSL_NELEM(tbl_standard)); } /* @@ -309,8 +307,7 @@ main() ASN1_STRING_TABLE *tmp; int i, last_nid = -1; - for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { + for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) { if (tmp->nid < last_nid) { last_nid = 0; break; @@ -323,8 +320,7 @@ main() exit(0); } - for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) + for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, OBJ_nid2ln(tmp->nid)); diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index 718aa521c5..49f4e5abbf 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -107,8 +107,7 @@ static STACK_OF(EVP_PKEY_ASN1_METHOD) *app_methods = NULL; void main() { int i; - for (i = 0; - i < sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); i++) + for (i = 0; i < OSSL_NELEM(standard_methods); i++) fprintf(stderr, "Number %d id=%d (%s)\n", i, standard_methods[i]->pkey_id, OBJ_nid2sn(standard_methods[i]->pkey_id)); @@ -129,7 +128,7 @@ IMPLEMENT_OBJ_BSEARCH_CMP_FN(const EVP_PKEY_ASN1_METHOD *, int EVP_PKEY_asn1_get_count(void) { - int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); + int num = OSSL_NELEM(standard_methods); if (app_methods) num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods); return num; @@ -137,7 +136,7 @@ int EVP_PKEY_asn1_get_count(void) const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) { - int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); + int num = OSSL_NELEM(standard_methods); if (idx < 0) return NULL; if (idx < num) @@ -157,8 +156,7 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) if (idx >= 0) return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx); } - ret = OBJ_bsearch_ameth(&t, standard_methods, sizeof(standard_methods) - / sizeof(EVP_PKEY_ASN1_METHOD *)); + ret = OBJ_bsearch_ameth(&t, standard_methods, OSSL_NELEM(standard_methods)); if (!ret || !*ret) return NULL; return *ret; diff --git a/crypto/asn1/asn1_gen.c b/crypto/asn1/asn1_gen.c index 549bc5ef36..049515d1cf 100644 --- a/crypto/asn1/asn1_gen.c +++ b/crypto/asn1/asn1_gen.c @@ -620,7 +620,7 @@ static int asn1_str2tag(const char *tagstr, int len) len = strlen(tagstr); tntmp = tnst; - for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) { + for (i = 0; i < OSSL_NELEM(tnst); i++, tntmp++) { if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) return tntmp->tag; } diff --git a/crypto/bio/bss_file.c b/crypto/bio/bss_file.c index 0776383448..1da6b86181 100644 --- a/crypto/bio/bss_file.c +++ b/crypto/bio/bss_file.c @@ -148,7 +148,7 @@ BIO *BIO_new_file(const char *filename, const char *mode) if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0, wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1, - wmode, sizeof(wmode) / sizeof(wmode[0])) && + wmode, OSSL_NELEM(wmode)) && (file = _wfopen(wfilename, wmode)) == NULL && (errno == ENOENT || errno == EBADF) ) { diff --git a/crypto/bn/bn_dh.c b/crypto/bn/bn_dh.c index 1c007bb901..cfd8c067a8 100644 --- a/crypto/bn/bn_dh.c +++ b/crypto/bn/bn_dh.c @@ -57,6 +57,7 @@ */ #include "bn_lcl.h" +#include "e_os.h" #ifndef OPENSSL_NO_DH /* DH parameters from RFC5114 */ @@ -247,8 +248,8 @@ static const BN_ULONG dh2048_256_q[] = { /* Macro to make a BIGNUM from static data */ # define make_dh_bn(x) const BIGNUM _bignum_##x = { (BN_ULONG *) x, \ - sizeof(x)/sizeof(BN_ULONG),\ - sizeof(x)/sizeof(BN_ULONG),\ + OSSL_NELEM(x),\ + OSSL_NELEM(x),\ 0, BN_FLG_STATIC_DATA }; diff --git a/crypto/bn/bn_gf2m.c b/crypto/bn/bn_gf2m.c index 7c0d4afc71..c87c5d96f8 100644 --- a/crypto/bn/bn_gf2m.c +++ b/crypto/bn/bn_gf2m.c @@ -473,8 +473,8 @@ int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p) int arr[6]; bn_check_top(a); bn_check_top(p); - ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0])); - if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) { + ret = BN_GF2m_poly2arr(p, arr, OSSL_NELEM(arr)); + if (!ret || ret > (int)OSSL_NELEM(arr)) { BNerr(BN_F_BN_GF2M_MOD, BN_R_INVALID_LENGTH); return 0; } diff --git a/crypto/bn/bn_nist.c b/crypto/bn/bn_nist.c index 2c5596d173..af048d3a3b 100644 --- a/crypto/bn/bn_nist.c +++ b/crypto/bn/bn_nist.c @@ -379,8 +379,8 @@ int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, PTR_SIZE_INT mask; static const BIGNUM _bignum_nist_p_192_sqr = { (BN_ULONG *)_nist_p_192_sqr, - sizeof(_nist_p_192_sqr) / sizeof(_nist_p_192_sqr[0]), - sizeof(_nist_p_192_sqr) / sizeof(_nist_p_192_sqr[0]), + OSSL_NELEM(_nist_p_192_sqr), + OSSL_NELEM(_nist_p_192_sqr), 0, BN_FLG_STATIC_DATA }; @@ -524,8 +524,8 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } u; static const BIGNUM _bignum_nist_p_224_sqr = { (BN_ULONG *)_nist_p_224_sqr, - sizeof(_nist_p_224_sqr) / sizeof(_nist_p_224_sqr[0]), - sizeof(_nist_p_224_sqr) / sizeof(_nist_p_224_sqr[0]), + OSSL_NELEM(_nist_p_224_sqr), + OSSL_NELEM(_nist_p_224_sqr), 0, BN_FLG_STATIC_DATA }; @@ -705,8 +705,8 @@ int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } u; static const BIGNUM _bignum_nist_p_256_sqr = { (BN_ULONG *)_nist_p_256_sqr, - sizeof(_nist_p_256_sqr) / sizeof(_nist_p_256_sqr[0]), - sizeof(_nist_p_256_sqr) / sizeof(_nist_p_256_sqr[0]), + OSSL_NELEM(_nist_p_256_sqr), + OSSL_NELEM(_nist_p_256_sqr), 0, BN_FLG_STATIC_DATA }; @@ -951,8 +951,8 @@ int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, } u; static const BIGNUM _bignum_nist_p_384_sqr = { (BN_ULONG *)_nist_p_384_sqr, - sizeof(_nist_p_384_sqr) / sizeof(_nist_p_384_sqr[0]), - sizeof(_nist_p_384_sqr) / sizeof(_nist_p_384_sqr[0]), + OSSL_NELEM(_nist_p_384_sqr), + OSSL_NELEM(_nist_p_384_sqr), 0, BN_FLG_STATIC_DATA }; @@ -1209,8 +1209,8 @@ int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, PTR_SIZE_INT mask; static const BIGNUM _bignum_nist_p_521_sqr = { (BN_ULONG *)_nist_p_521_sqr, - sizeof(_nist_p_521_sqr) / sizeof(_nist_p_521_sqr[0]), - sizeof(_nist_p_521_sqr) / sizeof(_nist_p_521_sqr[0]), + OSSL_NELEM(_nist_p_521_sqr), + OSSL_NELEM(_nist_p_521_sqr), 0, BN_FLG_STATIC_DATA }; diff --git a/crypto/bn/bn_srp.c b/crypto/bn/bn_srp.c index 0a39f2f7c1..5dd31fc7bf 100644 --- a/crypto/bn/bn_srp.c +++ b/crypto/bn/bn_srp.c @@ -1,4 +1,5 @@ #include "bn_lcl.h" +#include "e_os.h" #ifndef OPENSSL_NO_SRP @@ -37,8 +38,8 @@ static const BN_ULONG bn_group_1024_value[] = { const BIGNUM bn_group_1024 = { (BN_ULONG *)bn_group_1024_value, - (sizeof bn_group_1024_value) / sizeof(BN_ULONG), - (sizeof bn_group_1024_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_1024_value), + OSSL_NELEM(bn_group_1024_value), 0, BN_FLG_STATIC_DATA }; @@ -72,8 +73,8 @@ static const BN_ULONG bn_group_1536_value[] = { const BIGNUM bn_group_1536 = { (BN_ULONG *)bn_group_1536_value, - (sizeof bn_group_1536_value) / sizeof(BN_ULONG), - (sizeof bn_group_1536_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_1536_value), + OSSL_NELEM(bn_group_1536_value), 0, BN_FLG_STATIC_DATA }; @@ -115,8 +116,8 @@ static const BN_ULONG bn_group_2048_value[] = { const BIGNUM bn_group_2048 = { (BN_ULONG *)bn_group_2048_value, - (sizeof bn_group_2048_value) / sizeof(BN_ULONG), - (sizeof bn_group_2048_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_2048_value), + OSSL_NELEM(bn_group_2048_value), 0, BN_FLG_STATIC_DATA }; @@ -174,8 +175,8 @@ static const BN_ULONG bn_group_3072_value[] = { const BIGNUM bn_group_3072 = { (BN_ULONG *)bn_group_3072_value, - (sizeof bn_group_3072_value) / sizeof(BN_ULONG), - (sizeof bn_group_3072_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_3072_value), + OSSL_NELEM(bn_group_3072_value), 0, BN_FLG_STATIC_DATA }; @@ -249,8 +250,8 @@ static const BN_ULONG bn_group_4096_value[] = { const BIGNUM bn_group_4096 = { (BN_ULONG *)bn_group_4096_value, - (sizeof bn_group_4096_value) / sizeof(BN_ULONG), - (sizeof bn_group_4096_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_4096_value), + OSSL_NELEM(bn_group_4096_value), 0, BN_FLG_STATIC_DATA }; @@ -356,8 +357,8 @@ static const BN_ULONG bn_group_6144_value[] = { const BIGNUM bn_group_6144 = { (BN_ULONG *)bn_group_6144_value, - (sizeof bn_group_6144_value) / sizeof(BN_ULONG), - (sizeof bn_group_6144_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_6144_value), + OSSL_NELEM(bn_group_6144_value), 0, BN_FLG_STATIC_DATA }; @@ -495,8 +496,8 @@ static const BN_ULONG bn_group_8192_value[] = { const BIGNUM bn_group_8192 = { (BN_ULONG *)bn_group_8192_value, - (sizeof bn_group_8192_value) / sizeof(BN_ULONG), - (sizeof bn_group_8192_value) / sizeof(BN_ULONG), + OSSL_NELEM(bn_group_8192_value), + OSSL_NELEM(bn_group_8192_value), 0, BN_FLG_STATIC_DATA }; diff --git a/crypto/ec/ec_curve.c b/crypto/ec/ec_curve.c index 8bba3bcb83..d0f1fcb2fd 100644 --- a/crypto/ec/ec_curve.c +++ b/crypto/ec/ec_curve.c @@ -74,6 +74,7 @@ #include #include #include +#include "e_os.h" typedef struct { int field_type, /* either NID_X9_62_prime_field or @@ -3022,7 +3023,7 @@ static const ec_list_element curve_list[] = { "RFC 5639 curve over a 512 bit prime field"}, }; -#define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element)) +#define curve_list_length OSSL_NELEM(curve_list) static EC_GROUP *ec_group_new_from_data(const ec_list_element curve) { @@ -3194,7 +3195,7 @@ static EC_NIST_NAME nist_curves[] = { const char *EC_curve_nid2nist(int nid) { size_t i; - for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) { + for (i = 0; i < OSSL_NELEM(nist_curves); i++) { if (nist_curves[i].nid == nid) return nist_curves[i].name; } @@ -3204,7 +3205,7 @@ const char *EC_curve_nid2nist(int nid) int EC_curve_nist2nid(const char *name) { size_t i; - for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) { + for (i = 0; i < OSSL_NELEM(nist_curves); i++) { if (!strcmp(nist_curves[i].name, name)) return nist_curves[i].nid; } diff --git a/crypto/evp/evp_pbe.c b/crypto/evp/evp_pbe.c index 7a716372c1..6128a73620 100644 --- a/crypto/evp/evp_pbe.c +++ b/crypto/evp/evp_pbe.c @@ -130,7 +130,7 @@ int main(int argc, char **argv) * OpenSSL_add_all_algorithms(); */ - for (i = 0; i < sizeof(builtin_pbe) / sizeof(EVP_PBE_CTL); i++) { + for (i = 0; i < OSSL_NELEM(builtin_pbe); i++) { tpbe = builtin_pbe + i; fprintf(stderr, "%d %d %s ", tpbe->pbe_type, tpbe->pbe_nid, OBJ_nid2sn(tpbe->pbe_nid)); @@ -276,8 +276,7 @@ int EVP_PBE_find(int type, int pbe_nid, pbetmp = sk_EVP_PBE_CTL_value(pbe_algs, i); } if (pbetmp == NULL) { - pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe, - sizeof(builtin_pbe) / sizeof(EVP_PBE_CTL)); + pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe, OSSL_NELEM(builtin_pbe)); } if (pbetmp == NULL) return 0; diff --git a/crypto/objects/obj_xref.c b/crypto/objects/obj_xref.c index b752a2c5be..10ce6397d6 100644 --- a/crypto/objects/obj_xref.c +++ b/crypto/objects/obj_xref.c @@ -59,6 +59,7 @@ #include #include "obj_xref.h" +#include "e_os.h" DECLARE_STACK_OF(nid_triple) STACK_OF(nid_triple) *sig_app, *sigx_app; @@ -102,8 +103,7 @@ int OBJ_find_sigid_algs(int signid, int *pdig_nid, int *ppkey_nid) } #ifndef OBJ_XREF_TEST2 if (rv == NULL) { - rv = OBJ_bsearch_sig(&tmp, sigoid_srt, - sizeof(sigoid_srt) / sizeof(nid_triple)); + rv = OBJ_bsearch_sig(&tmp, sigoid_srt, OSSL_NELEM(sigoid_srt)); } #endif if (rv == NULL) @@ -133,9 +133,7 @@ int OBJ_find_sigid_by_algs(int *psignid, int dig_nid, int pkey_nid) } #ifndef OBJ_XREF_TEST2 if (rv == NULL) { - rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, - sizeof(sigoid_srt_xref) / sizeof(nid_triple *) - ); + rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, OSSL_NELEM(sigoid_srt_xref)); } #endif if (rv == NULL) @@ -198,12 +196,12 @@ main() int i, rv; # ifdef OBJ_XREF_TEST2 - for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) { + for (i = 0; i < OSSL_NELEM(sigoid_srt); i++) { OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1], sigoid_srt[i][2]); } # endif - for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) { + for (i = 0; i < OSSL_NELEM(sigoid_srt); i++) { n1 = sigoid_srt[i][0]; rv = OBJ_find_sigid_algs(n1, &n2, &n3); printf("Forward: %d, %s %s %s\n", rv, diff --git a/crypto/rand/rand_unix.c b/crypto/rand/rand_unix.c index 732ba3b31b..4332270004 100644 --- a/crypto/rand/rand_unix.c +++ b/crypto/rand/rand_unix.c @@ -250,7 +250,7 @@ int RAND_poll(void) # endif # ifdef DEVRANDOM static const char *randomfiles[] = { DEVRANDOM }; - struct stat randomstats[sizeof(randomfiles) / sizeof(randomfiles[0])]; + struct stat randomstats[OSSL_NELEM(randomfiles)]; int fd; unsigned int i; # endif @@ -267,8 +267,7 @@ int RAND_poll(void) * out of random entries. */ - for (i = 0; (i < sizeof(randomfiles) / sizeof(randomfiles[0])) && - (n < ENTROPY_NEEDED); i++) { + for (i = 0; (i < OSSL_NELEM(randomfiles)) && (n < ENTROPY_NEEDED); i++) { if ((fd = open(randomfiles[i], O_RDONLY # ifdef O_NONBLOCK | O_NONBLOCK diff --git a/crypto/ts/ts_rsp_print.c b/crypto/ts/ts_rsp_print.c index d64f2f4e4a..0a3e4973c8 100644 --- a/crypto/ts/ts_rsp_print.c +++ b/crypto/ts/ts_rsp_print.c @@ -130,8 +130,7 @@ int TS_STATUS_INFO_print_bio(BIO *bio, TS_STATUS_INFO *a) /* Printing status code. */ BIO_printf(bio, "Status: "); status = ASN1_INTEGER_get(a->status); - if (0 <= status - && status < (long)(sizeof(status_map) / sizeof(status_map[0]))) + if (0 <= status && status < (long)OSSL_NELEM(status_map)) BIO_printf(bio, "%s\n", status_map[status]); else BIO_printf(bio, "out of bounds\n"); diff --git a/crypto/ts/ts_rsp_verify.c b/crypto/ts/ts_rsp_verify.c index a89f9cbdfa..8381d4148b 100644 --- a/crypto/ts/ts_rsp_verify.c +++ b/crypto/ts/ts_rsp_verify.c @@ -101,7 +101,7 @@ static const char *TS_status_text[] = { "granted", "revocationNotification" }; -#define TS_STATUS_TEXT_SIZE (sizeof(TS_status_text)/sizeof(*TS_status_text)) +#define TS_STATUS_TEXT_SIZE OSSL_NELEM(TS_status_text) /* * This must be greater or equal to the sum of the strings in TS_status_text diff --git a/crypto/x509/x509_trs.c b/crypto/x509/x509_trs.c index 92ea2b586f..6632f9b9de 100644 --- a/crypto/x509/x509_trs.c +++ b/crypto/x509/x509_trs.c @@ -94,7 +94,7 @@ static X509_TRUST trstandard[] = { {X509_TRUST_TSA, 0, trust_1oidany, "TSA server", NID_time_stamp, NULL} }; -#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST)) +#define X509_TRUST_COUNT OSSL_NELEM(trstandard) static STACK_OF(X509_TRUST) *trtable = NULL; diff --git a/crypto/x509/x509_vpm.c b/crypto/x509/x509_vpm.c index 6305406756..b9a974136c 100644 --- a/crypto/x509/x509_vpm.c +++ b/crypto/x509/x509_vpm.c @@ -601,7 +601,7 @@ int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param) int X509_VERIFY_PARAM_get_count(void) { - int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM); + int num = OSSL_NELEM(default_table); if (param_table) num += sk_X509_VERIFY_PARAM_num(param_table); return num; @@ -609,7 +609,7 @@ int X509_VERIFY_PARAM_get_count(void) const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id) { - int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM); + int num = OSSL_NELEM(default_table); if (id < num) return default_table + id; return sk_X509_VERIFY_PARAM_value(param_table, id - num); @@ -626,9 +626,7 @@ const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name) if (idx != -1) return sk_X509_VERIFY_PARAM_value(param_table, idx); } - return OBJ_bsearch_table(&pm, default_table, - sizeof(default_table) / - sizeof(X509_VERIFY_PARAM)); + return OBJ_bsearch_table(&pm, default_table, OSSL_NELEM(default_table)); } void X509_VERIFY_PARAM_table_cleanup(void) diff --git a/crypto/x509v3/tabtest.c b/crypto/x509v3/tabtest.c index 145dc9de56..65209db972 100644 --- a/crypto/x509v3/tabtest.c +++ b/crypto/x509v3/tabtest.c @@ -72,7 +72,7 @@ main() { int i, prev = -1, bad = 0; X509V3_EXT_METHOD **tmp; - i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *); + i = OSSL_NELEM(standard_exts); if (i != STANDARD_EXTENSION_COUNT) fprintf(stderr, "Extension number invalid expecting %d\n", i); tmp = standard_exts; diff --git a/crypto/x509v3/v3_purp.c b/crypto/x509v3/v3_purp.c index d51f93f3f7..5cee586990 100644 --- a/crypto/x509v3/v3_purp.c +++ b/crypto/x509v3/v3_purp.c @@ -108,7 +108,7 @@ static X509_PURPOSE xstandard[] = { NULL}, }; -#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE)) +#define X509_PURPOSE_COUNT OSSL_NELEM(xstandard) static STACK_OF(X509_PURPOSE) *xptable = NULL; @@ -334,8 +334,7 @@ int X509_supported_extension(X509_EXTENSION *ex) if (ex_nid == NID_undef) return 0; - if (OBJ_bsearch_nid(&ex_nid, supported_nids, - sizeof(supported_nids) / sizeof(int))) + if (OBJ_bsearch_nid(&ex_nid, supported_nids, OSSL_NELEM(supported_nids))) return 1; return 0; } -- cgit v1.2.3