realloc of NULL is like malloc

ANSI C, and OpenSSL's malloc wrapper do this, also.

Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
Rich Salz
2015-04-28 16:34:52 -04:00
parent b196e7d936
commit 2d29e2df0c
8 changed files with 11 additions and 36 deletions

View File

@@ -114,10 +114,7 @@ size_t BUF_MEM_grow(BUF_MEM *str, size_t len)
return 0;
}
n = (len + 3) / 3 * 4;
if (str->data == NULL)
ret = OPENSSL_malloc(n);
else
ret = OPENSSL_realloc(str->data, n);
ret = OPENSSL_realloc(str->data, n);
if (ret == NULL) {
BUFerr(BUF_F_BUF_MEM_GROW, ERR_R_MALLOC_FAILURE);
len = 0;
@@ -151,10 +148,7 @@ size_t BUF_MEM_grow_clean(BUF_MEM *str, size_t len)
return 0;
}
n = (len + 3) / 3 * 4;
if (str->data == NULL)
ret = OPENSSL_malloc(n);
else
ret = OPENSSL_realloc_clean(str->data, str->max, n);
ret = OPENSSL_realloc_clean(str->data, str->max, n);
if (ret == NULL) {
BUFerr(BUF_F_BUF_MEM_GROW_CLEAN, ERR_R_MALLOC_FAILURE);
len = 0;