X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Fstack%2Fstack.c;h=d486f335b2ebec07c9bfef6e2a9890ddfc61a434;hb=1da12e34ed69cec206f3a251a1e62ceeb694a6ea;hp=efabe166edbc6e851eb38a762472a8cc66f4d71f;hpb=b4faea50c35d92a67d1369355b49cc3efba78406;p=openssl.git diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c index efabe166ed..d486f335b2 100644 --- a/crypto/stack/stack.c +++ b/crypto/stack/stack.c @@ -1,4 +1,3 @@ -/* crypto/stack/stack.c */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,7 +55,7 @@ * [including the GNU Public Licence.] */ #include -#include "cryptlib.h" +#include "internal/cryptlib.h" #include #include @@ -71,8 +70,6 @@ struct stack_st { #undef MIN_NODES #define MIN_NODES 4 -const char STACK_version[] = "Stack" OPENSSL_VERSION_PTEXT; - #include int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const void *))) @@ -152,19 +149,15 @@ _STACK *sk_new_null(void) _STACK *sk_new(int (*c) (const void *, const void *)) { _STACK *ret; - int i; - if ((ret = OPENSSL_malloc(sizeof(_STACK))) == NULL) + if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL) goto err; - if ((ret->data = OPENSSL_malloc(sizeof(*ret->data) * MIN_NODES)) == NULL) + if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL) goto err; - for (i = 0; i < MIN_NODES; i++) - ret->data[i] = NULL; ret->comp = c; ret->num_alloc = MIN_NODES; - ret->num = 0; - ret->sorted = 0; return (ret); + err: OPENSSL_free(ret); return (NULL); @@ -296,7 +289,7 @@ void sk_zero(_STACK *st) return; if (st->num <= 0) return; - memset((char *)st->data, 0, sizeof(*st->data) * st->num); + memset(st->data, 0, sizeof(*st->data) * st->num); st->num = 0; } @@ -343,7 +336,7 @@ void *sk_set(_STACK *st, int i, void *value) void sk_sort(_STACK *st) { - if (st && !st->sorted) { + if (st && !st->sorted && st->comp != NULL) { int (*comp_func) (const void *, const void *); /*