Changes from the Kerbnet release by Cygnus
authorEzra Peisach <epeisach@mit.edu>
Thu, 14 Aug 1997 15:38:14 +0000 (15:38 +0000)
committerEzra Peisach <epeisach@mit.edu>
Thu, 14 Aug 1997 15:38:14 +0000 (15:38 +0000)
        * asn1buf.h (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
        asn1buf_ensure_space, asn1buf_len): Add macro versions.
        (asn1buf_insert_octet) [__GNUC__ >= 2]: Ditto, using a GNU C
        extension.
        * asn1buf.c (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
        asn1buf_ensure_space, asn1buf_len, asn1buf_insert_octet): Undef
        macros before defining as functions.
[Kerbnet changes made by raeburn@cygnus.com]

        * asn1buf.h (asn1buf_expand): Remove "const" from int arg in
        prototype.

        * asn1buf.c (asn1buf_remove_charstring, asn1buf_create,
        asn1buf_remove_octetstring, asn12krb5_buf): Call malloc instead of
        calloc.
        (asn1buf_unparse, asn1buf_hex_unparse): Ditto.  Also don't
        allocate extra byte, since sizeof(STRING) does count the trailing
        null.
        (asn1buf_expand): Adjust bound based on increment
        value used, not value specified by caller.

[Kerbnet changes made by raeburn@cygnus.com]

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10174 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/asn.1/ChangeLog
src/lib/krb5/asn.1/asn1buf.c
src/lib/krb5/asn.1/asn1buf.h

index b1d5bf78960d4a1c3bcb8600fe5187c57e0130b8..c3b56a751e74594b3a4221ea28a904aaf4855742 100644 (file)
@@ -1,3 +1,30 @@
+Thu Jul 31 15:38:10 1997  Ezra Peisach  <epeisach@kangaroo.mit.edu>
+
+        * asn1buf.h (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
+        asn1buf_ensure_space, asn1buf_len): Add macro versions.
+        (asn1buf_insert_octet) [__GNUC__ >= 2]: Ditto, using a GNU C
+        extension.
+        * asn1buf.c (asn1buf_remove_octet, asn1buf_size, asn1buf_free,
+        asn1buf_ensure_space, asn1buf_len, asn1buf_insert_octet): Undef
+        macros before defining as functions.
+       [Kerbnet changes made by raeburn@cygnus.com]
+
+Thu Jul 31 12:34:43 1997  Ezra Peisach  <epeisach@mit.edu>
+
+        * asn1buf.h (asn1buf_expand): Remove "const" from int arg in
+        prototype.
+
+        * asn1buf.c (asn1buf_remove_charstring, asn1buf_create,
+        asn1buf_remove_octetstring, asn12krb5_buf): Call malloc instead of
+        calloc.
+        (asn1buf_unparse, asn1buf_hex_unparse): Ditto.  Also don't
+        allocate extra byte, since sizeof(STRING) does count the trailing
+        null.
+        (asn1buf_expand): Adjust bound based on increment 
+        value used, not value specified by caller.
+
+       [Kerbnet changes made by raeburn@cygnus.com]
+
 Thu Jul 31 11:17:06 1997  Ezra Peisach  <epeisach@mit.edu>
 
        * Makefile.in (SRCS): Add / after $(srcdir) in SRCS line.
index 822b26377d6fb200011f1191213f897fced956a0..94b4ac418d16b8ed6059db84707b24f6de2409fa 100644 (file)
@@ -54,7 +54,7 @@
 asn1_error_code asn1buf_create(buf)
      asn1buf ** buf;
 {
-  *buf = (asn1buf*)calloc(1,sizeof(asn1buf));
+  *buf = (asn1buf*)malloc(sizeof(asn1buf));
   if (*buf == NULL) return ENOMEM;
   (*buf)->base = NULL;
   (*buf)->bound = NULL;
@@ -105,6 +105,9 @@ asn1_error_code asn1buf_destroy(buf)
   return 0;
 }
 
+#ifdef asn1buf_insert_octet
+#undef asn1buf_insert_octet
+#endif
 asn1_error_code asn1buf_insert_octet(buf, o)
      asn1buf * buf;
      const int o;
@@ -148,6 +151,7 @@ asn1_error_code asn1buf_insert_charstring(buf, len, s)
   return 0;
 }
 
+#undef asn1buf_remove_octet
 asn1_error_code asn1buf_remove_octet(buf, o)
      asn1buf * buf;
      asn1_octet * o;
@@ -169,7 +173,7 @@ asn1_error_code asn1buf_remove_octetstring(buf, len, s)
       *s = 0;
       return 0;
   }
-  *s = (asn1_octet*)calloc(len,sizeof(asn1_octet));
+  *s = (asn1_octet*)malloc(len*sizeof(asn1_octet));
   if (*s == NULL)
       return ENOMEM;
   for(i=0; i<len; i++)
@@ -190,7 +194,7 @@ asn1_error_code asn1buf_remove_charstring(buf, len, s)
       *s = 0;
       return 0;
   }
-  *s = (char*)calloc(len,sizeof(char));
+  *s = (char*)malloc(len*sizeof(char));
   if (*s == NULL) return ENOMEM;
   for(i=0; i<len; i++)
     (*s)[i] = (char)(buf->next)[i];
@@ -230,7 +234,7 @@ asn1_error_code asn12krb5_buf(buf, code)
   (*code)->data = NULL;
   (*code)->length = 0;
   (*code)->length = asn1buf_len(buf);
-  (*code)->data = (char*)calloc(((*code)->length)+1,sizeof(char));
+  (*code)->data = (char*)malloc((((*code)->length)+1)*sizeof(char));
   for(i=0; i < (*code)->length; i++)
     ((*code)->data)[i] = (buf->base)[((*code)->length)-i-1];
   ((*code)->data)[(*code)->length] = '\0';
@@ -248,11 +252,11 @@ asn1_error_code asn1buf_unparse(buf, s)
 {
   if(*s != NULL) free(*s);
   if(buf == NULL){
-    *s = calloc(sizeof("<NULL>")+1, sizeof(char));
+    *s = malloc(sizeof("<NULL>"));
     if(*s == NULL) return ENOMEM;
     strcpy(*s,"<NULL>");
   }else if(buf->base == NULL){
-    *s = calloc(sizeof("<EMPTY>")+1, sizeof(char));
+    *s = malloc(sizeof("<EMPTY>"));
     if(*s == NULL) return ENOMEM;
     strcpy(*s,"<EMPTY>");
   }else{
@@ -279,18 +283,18 @@ asn1_error_code asn1buf_hex_unparse(buf, s)
   if(*s != NULL) free(*s);
 
   if(buf == NULL){
-    *s = calloc(sizeof("<NULL>")+1, sizeof(char));
+    *s = malloc(sizeof("<NULL>"));
     if(*s == NULL) return ENOMEM;
     strcpy(*s,"<NULL>");
   }else if(buf->base == NULL){
-    *s = calloc(sizeof("<EMPTY>")+1, sizeof(char));
+    *s = malloc(sizeof("<EMPTY>"));
     if(*s == NULL) return ENOMEM;
     strcpy(*s,"<EMPTY>");
   }else{
     int length = asn1buf_len(buf);
     int i;
 
-    *s = calloc(3*length, sizeof(char));
+    *s = malloc(3*length);
     if(*s == NULL) return ENOMEM;
     for(i = length-1; i >= 0; i--){
       (*s)[3*(length-i-1)] = hexchar(((buf->base)[i]&0xF0)>>4);
@@ -305,6 +309,7 @@ asn1_error_code asn1buf_hex_unparse(buf, s)
 /****************************************************************/
 /* Private Procedures */
 
+#undef asn1buf_size
 int asn1buf_size(buf)
      const asn1buf * buf;
 {
@@ -312,6 +317,7 @@ int asn1buf_size(buf)
   return buf->bound - buf->base + 1;
 }
 
+#undef asn1buf_free
 int asn1buf_free(buf)
      const asn1buf * buf;
 {
@@ -319,6 +325,7 @@ int asn1buf_free(buf)
   else return buf->bound - buf->next + 1;
 }
 
+#undef asn1buf_ensure_space
 asn1_error_code asn1buf_ensure_space(buf, amount)
      asn1buf * buf;
      const int amount;
@@ -333,7 +340,7 @@ asn1_error_code asn1buf_ensure_space(buf, amount)
 
 asn1_error_code asn1buf_expand(buf, inc)
      asn1buf * buf;
-     const int inc;
+     int inc;
 {
 #define STANDARD_INCREMENT 200
   int next_offset = buf->next - buf->base;
@@ -341,22 +348,21 @@ asn1_error_code asn1buf_expand(buf, inc)
   if(buf->base == NULL) bound_offset = -1;
   else bound_offset = buf->bound - buf->base;
 
+  if (inc < STANDARD_INCREMENT)
+    inc = STANDARD_INCREMENT;
+
   if (buf->base == NULL)
-    buf->base = malloc((asn1buf_size(buf)+(inc>STANDARD_INCREMENT ?
-                                          inc : STANDARD_INCREMENT))
-                      * sizeof(asn1_octet));
+    buf->base = malloc((asn1buf_size(buf)+inc) * sizeof(asn1_octet));
   else
     buf->base = realloc(buf->base,
-                       (asn1buf_size(buf)+(inc>STANDARD_INCREMENT ?
-                                           inc : STANDARD_INCREMENT))
-                       * sizeof(asn1_octet));
+                       (asn1buf_size(buf)+inc) * sizeof(asn1_octet));
   if(buf->base == NULL) return ENOMEM;
-  buf->bound = (buf->base) + bound_offset + (inc > STANDARD_INCREMENT ?
-                                          inc : STANDARD_INCREMENT);
+  buf->bound = (buf->base) + bound_offset + inc;
   buf->next = (buf->base) + next_offset;
   return 0;
 }
 
+#undef asn1buf_len
 int asn1buf_len(buf)
      const asn1buf * buf;
 {
index f3f4a3f2e06f4d31e214a4e18226c23bcf40ab4a..1aad777cb49153dd6a030638b4cb1063b47a5fb7 100644 (file)
@@ -82,6 +82,12 @@ asn1_error_code asn1buf_insert_octet
 /* requires  *buf is allocated
    effects   Inserts o into the buffer *buf, expanding the buffer if
              necessary.  Returns ENOMEM memory is exhausted. */
+#if __GNUC__ >= 2
+#define asn1buf_insert_octet(BUF,O)                                    \
+  (asn1buf_ensure_space ((BUF),1)                                      \
+   ? /* leave this empty -- gcc returns value of first operand */      \
+   : (*(BUF)->next++ = (O), 0))
+#endif
 
 asn1_error_code asn1buf_insert_octetstring
        PROTOTYPE((asn1buf *buf, const int len, const asn1_octet *s));
@@ -105,6 +111,10 @@ asn1_error_code asn1buf_remove_octet
    effects   Returns *buf's current octet in *o and advances to
               the next octet.
             Returns ASN1_OVERRUN if *buf has already been exhuasted. */
+#define asn1buf_remove_octet(buf,o) \
+  (((buf)->next > (buf)->bound) \
+   ? ASN1_OVERRUN \
+   : ((*(o) = (asn1_octet)(*(((buf)->next)++))),0))
 
 asn1_error_code asn1buf_remove_octetstring
        PROTOTYPE((asn1buf *buf, const int len, asn1_octet **s));
@@ -155,11 +165,20 @@ int asn1buf_size
 /* requires  *buf has been created and not destroyed
    effects   Returns the total size 
        PROTOTYPE((in octets) of buf's octet buffer. */
+#define asn1buf_size(buf) \
+  (((buf) == NULL || (buf)->base == NULL) \
+   ? 0 \
+   : ((buf)->bound - (buf)->base + 1))
 
 int asn1buf_free
        PROTOTYPE((const asn1buf *buf));
 /* requires  *buf is allocated
    effects   Returns the number of unused, allocated octets in *buf. */
+#define asn1buf_free(buf) \
+  (((buf) == NULL || (buf)->base == NULL) \
+   ? 0 \
+   : ((buf)->bound - (buf)->next + 1))
+
 
 asn1_error_code asn1buf_ensure_space
        PROTOTYPE((asn1buf *buf, const int amount));
@@ -168,9 +187,14 @@ asn1_error_code asn1buf_ensure_space
    effects  If buf has less than amount octets of free space, then it is
             expanded to have at least amount octets of free space.
             Returns ENOMEM memory is exhausted. */
+#define asn1buf_ensure_space(buf,amount) \
+  ((asn1buf_free(buf) < (amount)) \
+   ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
+   : 0)
+
 
 asn1_error_code asn1buf_expand
-       PROTOTYPE((asn1buf *buf, const int inc));
+       PROTOTYPE((asn1buf *buf, int inc));
 /* requires  *buf is allocated
    modifies  *buf
    effects   Expands *buf by allocating space for inc more octets.
@@ -180,5 +204,6 @@ int asn1buf_len
        PROTOTYPE((const asn1buf *buf));
 /* requires  *buf is allocated
    effects   Returns the length of the encoding in *buf. */
+#define asn1buf_len(buf)       ((buf)->next - (buf)->base)
 
 #endif