From 4472f3d68a4cfdda378061fd79bb5cfbb348752d Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sat, 12 May 2018 17:44:31 +0000 Subject: Cleanup c2i_ASN1_BIT_STRING() code. Avoid overloading a variable to store both a value and an error code - we can simply inline the error calls (as done everywhere else). Remove a bunch of unnecessary parentheses and tidy a few other things. With input from tb@. ok inoguchi@ tb@ --- src/lib/libcrypto/asn1/a_bitstr.c | 43 +++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index 3800c218a1..7fa5af9bbb 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_bitstr.c,v 1.26 2018/05/12 17:39:05 jsing Exp $ */ +/* $OpenBSD: a_bitstr.c,v 1.27 2018/05/12 17:44:31 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -135,15 +135,15 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) int i; if (len < 1) { - i = ASN1_R_STRING_TOO_SHORT; + ASN1error(ASN1_R_STRING_TOO_SHORT); goto err; } - if ((a == NULL) || ((*a) == NULL)) { + if (a == NULL || *a == NULL) { if ((ret = ASN1_BIT_STRING_new()) == NULL) return (NULL); } else - ret = (*a); + ret = *a; p = *pp; i = *(p++); @@ -152,17 +152,17 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) goto err; } - /* We do this to preserve the settings. If we modify - * the settings, via the _set_bit function, we will recalculate - * on output */ - ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ - ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ - - if (len-- > 1) /* using one because of the bits left byte */ - { - s = malloc(len); - if (s == NULL) { - i = ERR_R_MALLOC_FAILURE; + /* + * We do this to preserve the settings. If we modify the settings, + * via the _set_bit function, we will recalculate on output. + */ + ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */ + ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | i); /* set */ + + /* using one because of the bits left byte */ + if (len-- > 1) { + if ((s = malloc(len)) == NULL) { + ASN1error(ERR_R_MALLOC_FAILURE); goto err; } memcpy(s, p, len); @@ -171,19 +171,22 @@ c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, const unsigned char **pp, long len) } else s = NULL; - ret->length = (int)len; free(ret->data); ret->data = s; + ret->length = (int)len; ret->type = V_ASN1_BIT_STRING; + if (a != NULL) - (*a) = ret; + *a = ret; + *pp = p; + return (ret); -err: - ASN1error(i); - if ((ret != NULL) && ((a == NULL) || (*a != ret))) + err: + if (a == NULL || *a != ret) ASN1_BIT_STRING_free(ret); + return (NULL); } -- cgit v1.2.3-55-g6feb