提交 7e1445b0 编写于 作者: F FdaSilvaYY 提交者: Rich Salz

Use directly zalloc in OPENSSL_sk_dup and OPENSSL_sk_deep_copy

Reviewed-by: NRichard Levitte <levitte@openssl.org>
Reviewed-by: NRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1244)
上级 3ce2fdab
...@@ -39,25 +39,20 @@ OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfu ...@@ -39,25 +39,20 @@ OPENSSL_sk_compfunc OPENSSL_sk_set_cmp_func(OPENSSL_STACK *sk, OPENSSL_sk_compfu
OPENSSL_STACK *OPENSSL_sk_dup(OPENSSL_STACK *sk) OPENSSL_STACK *OPENSSL_sk_dup(OPENSSL_STACK *sk)
{ {
OPENSSL_STACK *ret; OPENSSL_STACK *ret;
char **s;
if ((ret = OPENSSL_sk_new(sk->comp)) == NULL) if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
goto err; return NULL;
s = OPENSSL_realloc((char *)ret->data,
(unsigned int)sizeof(char *) * sk->num_alloc); /* direct structure assignment */
if (s == NULL) *ret = *sk;
goto err;
ret->data = s;
ret->num = sk->num; if ((ret->data = OPENSSL_malloc(sizeof(*ret->data) * sk->num_alloc)) == NULL)
goto err;
memcpy(ret->data, sk->data, sizeof(char *) * sk->num); memcpy(ret->data, sk->data, sizeof(char *) * sk->num);
ret->sorted = sk->sorted; return ret;
ret->num_alloc = sk->num_alloc;
ret->comp = sk->comp;
return (ret);
err: err:
OPENSSL_sk_free(ret); OPENSSL_sk_free(ret);
return (NULL); return NULL;
} }
OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_func, OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_func,
...@@ -67,18 +62,17 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_ ...@@ -67,18 +62,17 @@ OPENSSL_STACK *OPENSSL_sk_deep_copy(OPENSSL_STACK *sk, OPENSSL_sk_copyfunc copy_
int i; int i;
if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL) if ((ret = OPENSSL_malloc(sizeof(*ret))) == NULL)
return ret; return NULL;
ret->comp = sk->comp;
ret->sorted = sk->sorted; /* direct structure assignment */
ret->num = sk->num; *ret = *sk;
ret->num_alloc = sk->num > MIN_NODES ? sk->num : MIN_NODES; ret->num_alloc = sk->num > MIN_NODES ? sk->num : MIN_NODES;
ret->data = OPENSSL_malloc(sizeof(*ret->data) * ret->num_alloc); ret->data = OPENSSL_zalloc(sizeof(*ret->data) * ret->num_alloc);
if (ret->data == NULL) { if (ret->data == NULL) {
OPENSSL_free(ret); OPENSSL_free(ret);
return NULL; return NULL;
} }
for (i = 0; i < ret->num_alloc; i++)
ret->data[i] = NULL;
for (i = 0; i < ret->num; ++i) { for (i = 0; i < ret->num; ++i) {
if (sk->data[i] == NULL) if (sk->data[i] == NULL)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册