From 89e34462d6c789038010ea62344815cd8fa9f3c1 Mon Sep 17 00:00:00 2001 From: miod Date: Sun, 18 May 2014 19:35:04 +0000 Subject: [PATCH] If you need to allocate `a + b' bytes of memory, then don't allocate `a + b*2', this is confusing and unnecessary. Help (coz I got confused) and ok guenther@ beck@ --- lib/libcrypto/asn1/f_enum.c | 4 ++-- lib/libcrypto/asn1/f_int.c | 4 ++-- lib/libcrypto/asn1/f_string.c | 4 ++-- lib/libssl/src/crypto/asn1/f_enum.c | 4 ++-- lib/libssl/src/crypto/asn1/f_int.c | 4 ++-- lib/libssl/src/crypto/asn1/f_string.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/libcrypto/asn1/f_enum.c b/lib/libcrypto/asn1/f_enum.c index c7b81ccbc95..14b609ebc8e 100644 --- a/lib/libcrypto/asn1/f_enum.c +++ b/lib/libcrypto/asn1/f_enum.c @@ -154,14 +154,14 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = realloc(s, (unsigned int)num + i * 2); + sp = realloc(s, (unsigned int)num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { diff --git a/lib/libcrypto/asn1/f_int.c b/lib/libcrypto/asn1/f_int.c index 283860d72d5..192e2f374f4 100644 --- a/lib/libcrypto/asn1/f_int.c +++ b/lib/libcrypto/asn1/f_int.c @@ -158,14 +158,14 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = OPENSSL_realloc_clean(s, slen, num + i * 2); + sp = OPENSSL_realloc_clean(s, slen, num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { diff --git a/lib/libcrypto/asn1/f_string.c b/lib/libcrypto/asn1/f_string.c index 0a1f136b4e7..163fca08c1d 100644 --- a/lib/libcrypto/asn1/f_string.c +++ b/lib/libcrypto/asn1/f_string.c @@ -150,14 +150,14 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = realloc(s, (unsigned int)num + i * 2); + sp = realloc(s, (unsigned int)num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { diff --git a/lib/libssl/src/crypto/asn1/f_enum.c b/lib/libssl/src/crypto/asn1/f_enum.c index c7b81ccbc95..14b609ebc8e 100644 --- a/lib/libssl/src/crypto/asn1/f_enum.c +++ b/lib/libssl/src/crypto/asn1/f_enum.c @@ -154,14 +154,14 @@ a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = realloc(s, (unsigned int)num + i * 2); + sp = realloc(s, (unsigned int)num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_ENUMERATED, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { diff --git a/lib/libssl/src/crypto/asn1/f_int.c b/lib/libssl/src/crypto/asn1/f_int.c index 283860d72d5..192e2f374f4 100644 --- a/lib/libssl/src/crypto/asn1/f_int.c +++ b/lib/libssl/src/crypto/asn1/f_int.c @@ -158,14 +158,14 @@ a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = OPENSSL_realloc_clean(s, slen, num + i * 2); + sp = OPENSSL_realloc_clean(s, slen, num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_INTEGER, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { diff --git a/lib/libssl/src/crypto/asn1/f_string.c b/lib/libssl/src/crypto/asn1/f_string.c index 0a1f136b4e7..163fca08c1d 100644 --- a/lib/libssl/src/crypto/asn1/f_string.c +++ b/lib/libssl/src/crypto/asn1/f_string.c @@ -150,14 +150,14 @@ a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) } i /= 2; if (num + i > slen) { - sp = realloc(s, (unsigned int)num + i * 2); + sp = realloc(s, (unsigned int)num + i); if (sp == NULL) { ASN1err(ASN1_F_A2I_ASN1_STRING, ERR_R_MALLOC_FAILURE); goto err; } s = sp; - slen = num + i * 2; + slen = num + i; } for (j = 0; j < i; j++, k += 2) { for (n = 0; n < 2; n++) { -- 2.20.1