diff options
author | Ben Laurie <ben@openssl.org> | 2008-10-12 14:32:47 +0000 |
---|---|---|
committer | Ben Laurie <ben@openssl.org> | 2008-10-12 14:32:47 +0000 |
commit | babb379849ffb4112792f266f92e9ebb2bd35332 (patch) | |
tree | d401aa7a4af8cc1180fe602711897a50d8feb74f /crypto/asn1 | |
parent | 6665ef303e837ed45654d1b5dd42123e7a51b0f4 (diff) |
Type-checked (and modern C compliant) OBJ_bsearch.
Diffstat (limited to 'crypto/asn1')
-rw-r--r-- | crypto/asn1/a_strnid.c | 18 | ||||
-rw-r--r-- | crypto/asn1/ameth_lib.c | 21 |
2 files changed, 24 insertions, 15 deletions
diff --git a/crypto/asn1/a_strnid.c b/crypto/asn1/a_strnid.c index ecf1d6004e..f0d5416660 100644 --- a/crypto/asn1/a_strnid.c +++ b/crypto/asn1/a_strnid.c @@ -67,7 +67,6 @@ static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; static void st_free(ASN1_STRING_TABLE *tbl); static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, const ASN1_STRING_TABLE * const *b); -static int table_cmp(const void *a, const void *b); /* This is the global mask for the mbstring functions: this is use to @@ -186,22 +185,25 @@ static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, return (*a)->nid - (*b)->nid; } -static int table_cmp(const void *a, const void *b) +DECLARE_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table_cmp); + +static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) { - const ASN1_STRING_TABLE *sa = a, *sb = b; - return sa->nid - sb->nid; + return a->nid - b->nid; } +IMPLEMENT_OBJ_BSEARCH_CMP_FN(ASN1_STRING_TABLE, ASN1_STRING_TABLE, table_cmp); + ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) { int idx; ASN1_STRING_TABLE *ttmp; ASN1_STRING_TABLE fnd; fnd.nid = nid; - ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd, - (char *)tbl_standard, - sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE), - sizeof(ASN1_STRING_TABLE), table_cmp); + ttmp = OBJ_bsearch(ASN1_STRING_TABLE, &fnd, + ASN1_STRING_TABLE, tbl_standard, + sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE), + table_cmp); if(ttmp) return ttmp; if(!stable) return NULL; idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); diff --git a/crypto/asn1/ameth_lib.c b/crypto/asn1/ameth_lib.c index 47cbdd28d0..300195bf95 100644 --- a/crypto/asn1/ameth_lib.c +++ b/crypto/asn1/ameth_lib.c @@ -112,12 +112,18 @@ void main() } #endif +DECLARE_OBJ_BSEARCH_CMP_FN(EVP_PKEY_ASN1_METHOD *, + const EVP_PKEY_ASN1_METHOD *, ameth_cmp); + static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a, - const EVP_PKEY_ASN1_METHOD * const *b) + const EVP_PKEY_ASN1_METHOD * const *b) { return ((*a)->pkey_id - (*b)->pkey_id); } +IMPLEMENT_OBJ_BSEARCH_CMP_FN(EVP_PKEY_ASN1_METHOD *, + const EVP_PKEY_ASN1_METHOD *, ameth_cmp); + int EVP_PKEY_asn1_get_count(void) { int num = sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *); @@ -139,7 +145,8 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx) static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type) { - EVP_PKEY_ASN1_METHOD tmp, *t = &tmp, **ret; + EVP_PKEY_ASN1_METHOD tmp, *t = &tmp; + const EVP_PKEY_ASN1_METHOD **ret; tmp.pkey_id = type; if (app_methods) { @@ -148,11 +155,11 @@ 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 = (EVP_PKEY_ASN1_METHOD **) OBJ_bsearch((char *)&t, - (char *)standard_methods, - sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *), - sizeof(EVP_PKEY_ASN1_METHOD *), - (int (*)(const void *, const void *))ameth_cmp); + ret = OBJ_bsearch(EVP_PKEY_ASN1_METHOD *, &t, + const EVP_PKEY_ASN1_METHOD *, standard_methods, + sizeof(standard_methods) + /sizeof(EVP_PKEY_ASN1_METHOD *), + ameth_cmp); if (!ret || !*ret) return NULL; return *ret; |