summaryrefslogtreecommitdiff
path: root/lib/libcrypto/stack/stack.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2000-12-15 02:58:48 +0000
committerBob Beck <beck@cvs.openbsd.org>2000-12-15 02:58:48 +0000
commit01c37e03996dffeff1618614755c6cc676899acb (patch)
tree988002fb9b1d859c10890511aa5273cfb00662dc /lib/libcrypto/stack/stack.c
parent9865f3ff77de9cfef0c5c8b0470daf6faa2f14af (diff)
openssl-engine-0.9.6 merge
Diffstat (limited to 'lib/libcrypto/stack/stack.c')
-rw-r--r--lib/libcrypto/stack/stack.c73
1 files changed, 47 insertions, 26 deletions
diff --git a/lib/libcrypto/stack/stack.c b/lib/libcrypto/stack/stack.c
index 58e9126339b..02857f04466 100644
--- a/lib/libcrypto/stack/stack.c
+++ b/lib/libcrypto/stack/stack.c
@@ -74,12 +74,12 @@
const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
-#define FP_ICC (int (*)(const void *,const void *))
#include <errno.h>
-int (*sk_set_cmp_func(STACK *sk, int (*c)()))(void)
+int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,const char * const *)))
+ (const char * const *, const char * const *)
{
- int (*old)()=sk->comp;
+ int (*old)(const char * const *,const char * const *)=sk->comp;
if (sk->comp != c)
sk->sorted=0;
@@ -94,7 +94,7 @@ STACK *sk_dup(STACK *sk)
char **s;
if ((ret=sk_new(sk->comp)) == NULL) goto err;
- s=(char **)Realloc((char *)ret->data,
+ s=(char **)OPENSSL_realloc((char *)ret->data,
(unsigned int)sizeof(char *)*sk->num_alloc);
if (s == NULL) goto err;
ret->data=s;
@@ -109,14 +109,19 @@ err:
return(NULL);
}
-STACK *sk_new(int (*c)())
+STACK *sk_new_null(void)
+ {
+ return sk_new((int (*)(const char * const *, const char * const *))0);
+ }
+
+STACK *sk_new(int (*c)(const char * const *, const char * const *))
{
STACK *ret;
int i;
- if ((ret=(STACK *)Malloc(sizeof(STACK))) == NULL)
+ if ((ret=(STACK *)OPENSSL_malloc(sizeof(STACK))) == NULL)
goto err0;
- if ((ret->data=(char **)Malloc(sizeof(char *)*MIN_NODES)) == NULL)
+ if ((ret->data=(char **)OPENSSL_malloc(sizeof(char *)*MIN_NODES)) == NULL)
goto err1;
for (i=0; i<MIN_NODES; i++)
ret->data[i]=NULL;
@@ -126,7 +131,7 @@ STACK *sk_new(int (*c)())
ret->sorted=0;
return(ret);
err1:
- Free(ret);
+ OPENSSL_free(ret);
err0:
return(NULL);
}
@@ -138,7 +143,7 @@ int sk_insert(STACK *st, char *data, int loc)
if(st == NULL) return 0;
if (st->num_alloc <= st->num+1)
{
- s=(char **)Realloc((char *)st->data,
+ s=(char **)OPENSSL_realloc((char *)st->data,
(unsigned int)sizeof(char *)*st->num_alloc*2);
if (s == NULL)
return(0);
@@ -207,7 +212,7 @@ int sk_find(STACK *st, char *data)
{
char **r;
int i;
- int (*comp_func)();
+ int (*comp_func)(const void *,const void *);
if(st == NULL) return -1;
if (st->comp == NULL)
@@ -219,13 +224,24 @@ int sk_find(STACK *st, char *data)
}
sk_sort(st);
if (data == NULL) return(-1);
- comp_func=(int (*)())st->comp;
+ /* This (and the "qsort" below) are the two places in OpenSSL
+ * where we need to convert from our standard (type **,type **)
+ * compare callback type to the (void *,void *) type required by
+ * bsearch. However, the "data" it is being called(back) with are
+ * not (type *) pointers, but the *pointers* to (type *) pointers,
+ * so we get our extra level of pointer dereferencing that way. */
+ comp_func=(int (*)(const void *,const void *))(st->comp);
r=(char **)bsearch(&data,(char *)st->data,
- st->num,sizeof(char *),FP_ICC comp_func);
+ st->num,sizeof(char *), comp_func);
if (r == NULL) return(-1);
i=(int)(r-st->data);
for ( ; i>0; i--)
- if ((*st->comp)(&(st->data[i-1]),&data) < 0)
+ /* This needs a cast because the type being pointed to from
+ * the "&" expressions are (char *) rather than (const char *).
+ * For an explanation, read:
+ * http://www.eskimo.com/~scs/C-faq/q11.10.html :-) */
+ if ((*st->comp)((const char * const *)&(st->data[i-1]),
+ (const char * const *)&data) < 0)
break;
return(i);
}
@@ -262,7 +278,7 @@ void sk_zero(STACK *st)
st->num=0;
}
-void sk_pop_free(STACK *st, void (*func)())
+void sk_pop_free(STACK *st, void (*func)(void *))
{
int i;
@@ -276,17 +292,17 @@ void sk_pop_free(STACK *st, void (*func)())
void sk_free(STACK *st)
{
if (st == NULL) return;
- if (st->data != NULL) Free(st->data);
- Free(st);
+ if (st->data != NULL) OPENSSL_free(st->data);
+ OPENSSL_free(st);
}
-int sk_num(STACK *st)
+int sk_num(const STACK *st)
{
if(st == NULL) return -1;
return st->num;
}
-char *sk_value(STACK *st, int i)
+char *sk_value(const STACK *st, int i)
{
if(st == NULL) return NULL;
return st->data[i];
@@ -299,13 +315,18 @@ char *sk_set(STACK *st, int i, char *value)
}
void sk_sort(STACK *st)
- {
- if (!st->sorted)
{
- int (*comp_func)();
-
- comp_func=(int (*)())st->comp;
- qsort(st->data,st->num,sizeof(char *),FP_ICC comp_func);
- st->sorted=1;
+ if (!st->sorted)
+ {
+ int (*comp_func)(const void *,const void *);
+
+ /* same comment as in sk_find ... previously st->comp was declared
+ * as a (void*,void*) callback type, but this made the population
+ * of the callback pointer illogical - our callbacks compare
+ * type** with type**, so we leave the casting until absolutely
+ * necessary (ie. "now"). */
+ comp_func=(int (*)(const void *,const void *))(st->comp);
+ qsort(st->data,st->num,sizeof(char *), comp_func);
+ st->sorted=1;
+ }
}
- }