summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2014-05-17 17:35:05 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2014-05-17 17:35:05 +0000
commit4e260113d12c1b4cc9b3bbb87a9154d9b13bd180 (patch)
treec723d4bfe2c065c65503854b1f41f6478e1a1e66
parent84f056db24ea54be4bf9bd3cf2462284ca521259 (diff)
simple reallocarray to check multiplies. ok guenther
-rw-r--r--lib/libcrypto/stack/stack.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/lib/libcrypto/stack/stack.c b/lib/libcrypto/stack/stack.c
index a409a7e9678..0224bfce745 100644
--- a/lib/libcrypto/stack/stack.c
+++ b/lib/libcrypto/stack/stack.c
@@ -98,8 +98,7 @@ sk_dup(_STACK *sk)
if ((ret = sk_new(sk->comp)) == NULL)
goto err;
- s = (char **)realloc((char *)ret->data,
- (unsigned int)sizeof(char *) * sk->num_alloc);
+ s = reallocarray(ret->data, sk->num_alloc, sizeof(char *));
if (s == NULL)
goto err;
ret->data = s;
@@ -131,7 +130,7 @@ sk_new(int (*c)(const void *, const void *))
if ((ret = malloc(sizeof(_STACK))) == NULL)
goto err;
- if ((ret->data = malloc(sizeof(char *) * MIN_NODES)) == NULL)
+ if ((ret->data = reallocarray(NULL, MIN_NODES, sizeof(char *))) == NULL)
goto err;
for (i = 0; i < MIN_NODES; i++)
ret->data[i] = NULL;
@@ -155,8 +154,7 @@ sk_insert(_STACK *st, void *data, int loc)
if (st == NULL)
return 0;
if (st->num_alloc <= st->num + 1) {
- s = realloc((char *)st->data,
- (unsigned int)sizeof(char *) * st->num_alloc * 2);
+ s = reallocarray(st->data, st->num_alloc, 2 * sizeof(char *));
if (s == NULL)
return (0);
st->data = s;
@@ -296,7 +294,7 @@ 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;
}