-/* crypto/stack/stack.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* [including the GNU Public Licence.]
*/
#include <stdio.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
#include <openssl/stack.h>
#include <openssl/objects.h>
#undef MIN_NODES
#define MIN_NODES 4
-const char STACK_version[] = "Stack" OPENSSL_VERSION_PTEXT;
-
#include <errno.h>
int (*sk_set_cmp_func(_STACK *sk, int (*c) (const void *, const 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);
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;
}
void sk_sort(_STACK *st)
{
- if (st && !st->sorted) {
+ if (st && !st->sorted && st->comp != NULL) {
int (*comp_func) (const void *, const void *);
/*