size_tification.
[openssl.git] / crypto / objects / obj_dat.c
index db88f5f98018731140d4a9617e402bff35c3d3a6..1582d61492280798b4429ce041948f8e9e0f74dd 100644 (file)
@@ -81,9 +81,10 @@ static const unsigned int ln_objs[1];
 static const unsigned int obj_objs[1];
 #endif
 
-static int sn_cmp(const void *a, const void *b);
-static int ln_cmp(const void *a, const void *b);
-static int obj_cmp(const void *a, const void *b);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
+DECLARE_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
+
 #define ADDED_DATA     0
 #define ADDED_SNAME    1
 #define ADDED_LNAME    2
@@ -99,19 +100,15 @@ DECLARE_LHASH_OF(ADDED_OBJ);
 static int new_nid=NUM_NID;
 static LHASH_OF(ADDED_OBJ) *added=NULL;
 
-static int sn_cmp(const void *a, const void *b)
-       {
-       const ASN1_OBJECT * const *ap = a;
-       const unsigned int *bp = b;
-       return(strcmp((*ap)->sn,nid_objs[*bp].sn));
-       }
+static int sn_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+       { return(strcmp((*a)->sn,nid_objs[*b].sn)); }
 
-static int ln_cmp(const void *a, const void *b)
-       { 
-       const ASN1_OBJECT * const *ap = a;
-       const unsigned int *bp = b;
-       return(strcmp((*ap)->ln,nid_objs[*bp].ln));
-       }
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, sn);
+
+static int ln_cmp(const ASN1_OBJECT * const *a, const unsigned int *b)
+       { return(strcmp((*a)->ln,nid_objs[*b].ln)); }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, ln);
 
 static unsigned long added_obj_hash(const ADDED_OBJ *ca)
        {
@@ -385,6 +382,19 @@ const char *OBJ_nid2ln(int n)
                }
        }
 
+static int obj_cmp(const ASN1_OBJECT * const *ap, const unsigned int *bp)
+       {
+       int j;
+       const ASN1_OBJECT *a= *ap;
+       const ASN1_OBJECT *b= &nid_objs[*bp];
+
+       j=(a->length - b->length);
+        if (j) return(j);
+       return(memcmp(a->data,b->data,a->length));
+       }
+
+IMPLEMENT_OBJ_BSEARCH_CMP_FN(const ASN1_OBJECT *, unsigned int, obj);
+
 int OBJ_obj2nid(const ASN1_OBJECT *a)
        {
        const unsigned int *op;
@@ -402,8 +412,7 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
                adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(const unsigned int *)OBJ_bsearch((const char *)&a,(const char *)obj_objs,
-               NUM_OBJ, sizeof(obj_objs[0]),obj_cmp);
+       op=OBJ_bsearch_obj(&a, obj_objs, NUM_OBJ);
        if (op == NULL)
                return(NID_undef);
        return(nid_objs[*op].nid);
@@ -422,7 +431,8 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
        unsigned char *buf;
        unsigned char *p;
        const unsigned char *cp;
-       int i, j;
+       size_t i;
+       size_t j;
 
        if(!no_name) {
                if( ((nid = OBJ_sn2nid(s)) != NID_undef) ||
@@ -432,7 +442,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
 
        /* Work out size of content octets */
        i=a2d_ASN1_OBJECT(NULL,0,s,-1);
-       if (i <= 0) {
+       if (i == 0) {
                /* Don't clear the error */
                /*ERR_clear_error();*/
                return NULL;
@@ -440,7 +450,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
        /* Work out total size */
        j = ASN1_object_size(0,i,V_ASN1_OBJECT);
 
-       if((buf=(unsigned char *)OPENSSL_malloc(j)) == NULL) return NULL;
+       if((buf=OPENSSL_malloc(j)) == NULL) return NULL;
 
        p = buf;
        /* Write out tag+length */
@@ -454,7 +464,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
        return op;
        }
 
-int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
+int OBJ_obj2txt(char *buf, size_t buf_len, const ASN1_OBJECT *a, int no_name)
 {
        int i,n=0,len,nid, first, use_bn;
        BIGNUM *bl;
@@ -499,7 +509,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
                                goto err;
                        if (use_bn)
                                {
-                               if (!BN_add_word(bl, c & 0x7f))
+                               if (!BN_add_word(bl, c & 0x7fU))
                                        goto err;
                                }
                        else
@@ -625,7 +635,8 @@ int OBJ_txt2nid(const char *s)
 
 int OBJ_ln2nid(const char *s)
        {
-       ASN1_OBJECT o,*oo= &o;
+       ASN1_OBJECT o;
+       const ASN1_OBJECT *oo= &o;
        ADDED_OBJ ad,*adp;
        const unsigned int *op;
 
@@ -637,15 +648,15 @@ int OBJ_ln2nid(const char *s)
                adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(const unsigned int*)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN,
-               sizeof(ln_objs[0]),ln_cmp);
+       op=OBJ_bsearch_ln(&oo, ln_objs, NUM_LN);
        if (op == NULL) return(NID_undef);
        return(nid_objs[*op].nid);
        }
 
 int OBJ_sn2nid(const char *s)
        {
-       ASN1_OBJECT o,*oo= &o;
+       ASN1_OBJECT o;
+       const ASN1_OBJECT *oo= &o;
        ADDED_OBJ ad,*adp;
        const unsigned int *op;
 
@@ -657,32 +668,23 @@ int OBJ_sn2nid(const char *s)
                adp=lh_ADDED_OBJ_retrieve(added,&ad);
                if (adp != NULL) return (adp->obj->nid);
                }
-       op=(const unsigned int *)OBJ_bsearch((char *)&oo,(char *)sn_objs,NUM_SN,
-               sizeof(sn_objs[0]),sn_cmp);
+       op=OBJ_bsearch_sn(&oo, sn_objs, NUM_SN);
        if (op == NULL) return(NID_undef);
        return(nid_objs[*op].nid);
        }
 
-static int obj_cmp(const void *ap, const void *bp)
-       {
-       int j;
-       const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap;
-       const ASN1_OBJECT *b= &nid_objs[*((const unsigned int *)bp)];
-
-       j=(a->length - b->length);
-        if (j) return(j);
-       return(memcmp(a->data,b->data,a->length));
-        }
-
-const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
-       int (*cmp)(const void *, const void *))
+const void *OBJ_bsearch_(const void *key, const void *base, int num, int size,
+                        int (*cmp)(const void *, const void *))
        {
-       return OBJ_bsearch_ex(key, base, num, size, cmp, 0);
+       return OBJ_bsearch_ex_(key, base, num, size, cmp, 0);
        }
 
-const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
-       int size, int (*cmp)(const void *, const void *), int flags)
+const void *OBJ_bsearch_ex_(const void *key, const void *base_, int num,
+                           int size,
+                           int (*cmp)(const void *, const void *),
+                           int flags)
        {
+       const char *base=base_;
        int l,h,i=0,c=0;
        const char *p = NULL;
 
@@ -781,12 +783,13 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
        int ok=0;
        ASN1_OBJECT *op=NULL;
        unsigned char *buf;
-       int i;
+       size_t i;
 
        i=a2d_ASN1_OBJECT(NULL,0,oid,-1);
-       if (i <= 0) return(0);
+       if (i == 0)
+           return 0;
 
-       if ((buf=(unsigned char *)OPENSSL_malloc(i)) == NULL)
+       if ((buf=OPENSSL_malloc(i)) == NULL)
                {
                OBJerr(OBJ_F_OBJ_CREATE,ERR_R_MALLOC_FAILURE);
                return(0);
@@ -794,7 +797,7 @@ int OBJ_create(const char *oid, const char *sn, const char *ln)
        i=a2d_ASN1_OBJECT(buf,i,oid,-1);
        if (i == 0)
                goto err;
-       op=(ASN1_OBJECT *)ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
+       op=ASN1_OBJECT_create(OBJ_new_nid(1),buf,i,sn,ln);
        if (op == NULL) 
                goto err;
        ok=OBJ_add_object(op);