summaryrefslogtreecommitdiffstats
path: root/lib/libcrypto/buffer/buffer.c
diff options
context:
space:
mode:
authorjsing <jsing@openbsd.org>2017-04-09 15:03:54 +0000
committerjsing <jsing@openbsd.org>2017-04-09 15:03:54 +0000
commit027ccf5329c0a626d5f824374ef6ff2fa3f4b437 (patch)
tree4f6d184940ed48d389c995a87b747ffcf1aae704 /lib/libcrypto/buffer/buffer.c
parentExplicitly test for NULL. (diff)
downloadwireguard-openbsd-027ccf5329c0a626d5f824374ef6ff2fa3f4b437.tar.xz
wireguard-openbsd-027ccf5329c0a626d5f824374ef6ff2fa3f4b437.zip
With recallocarray() BUF_MEM_grow() is essentially the same as
BUF_MEM_grow_clean() (the only difference is clearing on internal down sizing), so make it a wrapper. ok beck@ deraadt@
Diffstat (limited to 'lib/libcrypto/buffer/buffer.c')
-rw-r--r--lib/libcrypto/buffer/buffer.c30
1 files changed, 2 insertions, 28 deletions
diff --git a/lib/libcrypto/buffer/buffer.c b/lib/libcrypto/buffer/buffer.c
index 2e4959a58d6..f15b93d26c0 100644
--- a/lib/libcrypto/buffer/buffer.c
+++ b/lib/libcrypto/buffer/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.24 2017/03/16 13:29:56 jsing Exp $ */
+/* $OpenBSD: buffer.c,v 1.25 2017/04/09 15:03:54 jsing Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -97,33 +97,7 @@ BUF_MEM_free(BUF_MEM *a)
int
BUF_MEM_grow(BUF_MEM *str, size_t len)
{
- char *ret;
- size_t n;
-
- if (str->length >= len) {
- str->length = len;
- return (len);
- }
- if (str->max >= len) {
- str->length = len;
- return (len);
- }
- /* This limit is sufficient to ensure (len+3)/3*4 < 2**31 */
- if (len > LIMIT_BEFORE_EXPANSION) {
- BUFerror(ERR_R_MALLOC_FAILURE);
- return 0;
- }
- n = (len + 3) / 3 * 4;
- ret = recallocarray(str->data, str->max, n, 1);
- if (ret == NULL) {
- BUFerror(ERR_R_MALLOC_FAILURE);
- len = 0;
- } else {
- str->data = ret;
- str->max = n;
- str->length = len;
- }
- return (len);
+ return BUF_MEM_grow_clean(str, len);
}
int