Constify d2i, s2i, c2i and r2i functions and other associated
[openssl.git] / crypto / asn1 / a_d2i_fp.c
index 71b4a286113e45ff9fb8a4a0fa87677da4aa1113..2e99e4c69a78ed59b02ba81f0ff7974e84d39130 100644 (file)
@@ -107,14 +107,14 @@ err:
 void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
        {
        BUF_MEM *b = NULL;
-       unsigned char *p;
+       const unsigned char *p;
        void *ret=NULL;
        int len;
 
        len = asn1_d2i_read_bio(in, &b);
        if(len < 0) goto err;
 
-       p=(unsigned char *)b->data;
+       p=(const unsigned char *)b->data;
        ret=ASN1_item_d2i(x,&p,len, it);
 err:
        if (b != NULL) BUF_MEM_free(b);
@@ -146,10 +146,15 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
        unsigned char *p;
        int i;
        int ret=-1;
-       ASN1_CTX c;
+       ASN1_const_CTX c;
        int want=HEADER_SIZE;
        int eos=0;
+#if defined(__GNUC__) && defined(__ia64)
+       /* pathetic compiler bug in all known versions as of Nov. 2002 */
+       long off=0;
+#else
        int off=0;
+#endif
        int len=0;
 
        b=BUF_MEM_new();
@@ -226,13 +231,18 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
                                        ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
                                        goto err;
                                        }
-                               i=BIO_read(in,&(b->data[len]),want);
-                               if (i <= 0)
+                               while (want > 0)
                                        {
-                                       ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
-                                       goto err;
+                                       i=BIO_read(in,&(b->data[len]),want);
+                                       if (i <= 0)
+                                               {
+                                               ASN1err(ASN1_F_ASN1_D2I_BIO,
+                                                   ASN1_R_NOT_ENOUGH_DATA);
+                                               goto err;
+                                               }
+                                       len+=i;
+                                       want -= i;
                                        }
-                               len+=i;
                                }
                        off+=(int)c.slen;
                        if (eos <= 0)