diff options
author | Rich Salz <rsalz@openssl.org> | 2015-04-28 16:34:52 -0400 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2015-04-28 16:34:52 -0400 |
commit | 2d29e2df0c9040e139d68c8659ee0342a6ac3dd1 (patch) | |
tree | 1c204074c02b3e356e60b51abe82e4552983bc80 /crypto | |
parent | b196e7d936fb377d9c5b305748ac25ff0e53ef6d (diff) | |
download | openssl-2d29e2df0c9040e139d68c8659ee0342a6ac3dd1.tar.gz |
realloc of NULL is like malloc
ANSI C, and OpenSSL's malloc wrapper do this, also.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asn1/a_bitstr.c | 5 | ||||
-rw-r--r-- | crypto/asn1/asn1_lib.c | 6 | ||||
-rw-r--r-- | crypto/asn1/f_enum.c | 5 | ||||
-rw-r--r-- | crypto/asn1/f_int.c | 5 | ||||
-rw-r--r-- | crypto/asn1/f_string.c | 5 | ||||
-rw-r--r-- | crypto/bio/b_sock.c | 7 | ||||
-rw-r--r-- | crypto/buffer/buffer.c | 10 | ||||
-rw-r--r-- | crypto/err/err.c | 4 |
8 files changed, 11 insertions, 36 deletions
diff --git a/crypto/asn1/a_bitstr.c b/crypto/asn1/a_bitstr.c index 8a9e17cb27..ba243f1a5f 100644 --- a/crypto/asn1/a_bitstr.c +++ b/crypto/asn1/a_bitstr.c @@ -205,10 +205,7 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) if ((a->length < (w + 1)) || (a->data == NULL)) { if (!value) return (1); /* Don't need to set */ - if (a->data == NULL) - c = OPENSSL_malloc(w + 1); - else - c = OPENSSL_realloc_clean(a->data, a->length, w + 1); + c = OPENSSL_realloc_clean(a->data, a->length, w + 1); if (c == NULL) { ASN1err(ASN1_F_ASN1_BIT_STRING_SET_BIT, ERR_R_MALLOC_FAILURE); return 0; diff --git a/crypto/asn1/asn1_lib.c b/crypto/asn1/asn1_lib.c index 97f1d23da8..a892d7f063 100644 --- a/crypto/asn1/asn1_lib.c +++ b/crypto/asn1/asn1_lib.c @@ -317,11 +317,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) } if ((str->length < len) || (str->data == NULL)) { c = str->data; - if (c == NULL) - str->data = OPENSSL_malloc(len + 1); - else - str->data = OPENSSL_realloc(c, len + 1); - + str->data = OPENSSL_realloc(c, len + 1); if (str->data == NULL) { ASN1err(ASN1_F_ASN1_STRING_SET, ERR_R_MALLOC_FAILURE); str->data = c; diff --git a/crypto/asn1/f_enum.c b/crypto/asn1/f_enum.c index c623cdc784..2ec99a51a3 100644 --- a/crypto/asn1/f_enum.c +++ b/crypto/asn1/f_enum.c @@ -151,10 +151,7 @@ int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - if (s == NULL) - sp = OPENSSL_malloc((unsigned int)num + i * 2); - else - sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); + sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); if (s != NULL) diff --git a/crypto/asn1/f_int.c b/crypto/asn1/f_int.c index 39c9a61e59..f74252c45a 100644 --- a/crypto/asn1/f_int.c +++ b/crypto/asn1/f_int.c @@ -165,10 +165,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - if (s == NULL) - sp = OPENSSL_malloc((unsigned int)num + i * 2); - else - sp = OPENSSL_realloc_clean(s, slen, num + i * 2); + sp = OPENSSL_realloc_clean(s, slen, num + i * 2); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); if (s != NULL) diff --git a/crypto/asn1/f_string.c b/crypto/asn1/f_string.c index 6cb4cfdff9..53f8cf3a83 100644 --- a/crypto/asn1/f_string.c +++ b/crypto/asn1/f_string.c @@ -157,10 +157,7 @@ int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - if (s == NULL) - sp = OPENSSL_malloc((unsigned int)num + i * 2); - else - sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); + sp = OPENSSL_realloc(s, (unsigned int)num + i * 2); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE); if (s != NULL) diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index ca485d9c19..a4fded5ec2 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -673,12 +673,9 @@ int BIO_accept(int sock, char **addr) break; nl = strlen(h) + strlen(s) + 2; p = *addr; - if (p) { + if (p) *p = '\0'; - p = OPENSSL_realloc(p, nl); - } else { - p = OPENSSL_malloc(nl); - } + p = OPENSSL_realloc(p, nl); if (p == NULL) { BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); goto end; diff --git a/crypto/buffer/buffer.c b/crypto/buffer/buffer.c index 0859974e79..c77fdc5ccb 100644 --- a/crypto/buffer/buffer.c +++ b/crypto/buffer/buffer.c @@ -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; diff --git a/crypto/err/err.c b/crypto/err/err.c index 4752148169..ec7da22e5b 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -969,8 +969,8 @@ void ERR_add_error_vdata(int num, va_list args) if (p == NULL) { OPENSSL_free(str); return; - } else - str = p; + } + str = p; } BUF_strlcat(str, a, (size_t)s + 1); } |