Commit b6eb9827 authored by Dr. Stephen Henson's avatar Dr. Stephen Henson
Browse files

Add OSSL_NELEM macro.



Add OSSL_NELEM macro to e_os.h to determine the number of elements in an
array.

Reviewed-by: default avatarTim Hudson <tjh@openssl.org>
parent 31ff45aa
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -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));

+4 −6
Original line number Diff line number Diff line
@@ -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;
+1 −1
Original line number Diff line number Diff line
@@ -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;
    }
+1 −1
Original line number Diff line number Diff line
@@ -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)
            ) {
+3 −2
Original line number Diff line number Diff line
@@ -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 };


Loading