diff options
Diffstat (limited to 'crypto/stack/stack.c')
-rw-r--r-- | crypto/stack/stack.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/crypto/stack/stack.c b/crypto/stack/stack.c index 559085a7b8..fc755e36b6 100644 --- a/crypto/stack/stack.c +++ b/crypto/stack/stack.c @@ -111,16 +111,12 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(const OPENSSL_STACK *sk, OPENSSL_STACK *OPENSSL_sk_new_null(void) { - return OPENSSL_zalloc(sizeof(OPENSSL_STACK)); + return OPENSSL_sk_new_reserve(NULL, 0); } OPENSSL_STACK *OPENSSL_sk_new(OPENSSL_sk_compfunc c) { - OPENSSL_STACK *ret = OPENSSL_sk_new_null(); - - if (ret != NULL) - ret->comp = c; - return ret; + return OPENSSL_sk_new_reserve(c, 0); } /* @@ -203,6 +199,26 @@ static int sk_reserve(OPENSSL_STACK *st, int n, int exact) return 1; } +OPENSSL_STACK *OPENSSL_sk_new_reserve(OPENSSL_sk_compfunc c, int n) +{ + OPENSSL_STACK *st = OPENSSL_zalloc(sizeof(OPENSSL_STACK)); + + if (st == NULL) + return NULL; + + st->comp = c; + + if (n <= 0) + return st; + + if (!sk_reserve(st, n, 1)) { + OPENSSL_sk_free(st); + return NULL; + } + + return st; +} + int OPENSSL_sk_reserve(OPENSSL_STACK *st, int n) { if (st == NULL) |