RT783: Minor optimization to ASN1_INTEGER_set
authorFrédéric Giudicelli <groups@newpki.org>
Fri, 15 Aug 2014 02:34:49 +0000 (22:34 -0400)
committerRich Salz <rsalz@akamai.com>
Fri, 15 Aug 2014 14:54:43 +0000 (10:54 -0400)
Remove local variable and avoid extra assignment.

Reviewed-by: Emilia Kasper <emilia@silkandcyanide.net>
crypto/asn1/a_int.c

index 297c45a9ff12ebb54df717bd7c1f8487579daad4..b9f2ac1b05ce8769985c7f32b2b8aa0991313e9a 100644 (file)
@@ -337,9 +337,7 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
        int j,k;
        unsigned int i;
        unsigned char buf[sizeof(long)+1];
-       long d;
 
-       a->type=V_ASN1_INTEGER;
        if (a->length < (int)(sizeof(long)+1))
                {
                if (a->data != NULL)
@@ -352,18 +350,19 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
                ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE);
                return(0);
                }
-       d=v;
-       if (d < 0)
+       if (v < 0)
                {
-               d= -d;
+               v= -v;
                a->type=V_ASN1_NEG_INTEGER;
                }
+       else
+               a->type=V_ASN1_INTEGER;
 
        for (i=0; i<sizeof(long); i++)
                {
-               if (d == 0) break;
-               buf[i]=(int)d&0xff;
-               d>>=8;
+               if (v == 0) break;
+               buf[i]=(int)v&0xff;
+               v>>=8;
                }
        j=0;
        for (k=i-1; k >=0; k--)