Fix null ptr reference for freeReplyObject YAZ-773
[yaz-moved-to-github.git] / src / odr_cons.c
index c6d092c..7bf368a 100644 (file)
@@ -1,9 +1,6 @@
-/*
- * Copyright (C) 1995-2007, Index Data ApS
+/* This file is part of the YAZ toolkit.
+ * Copyright (C) Index Data
  * See the file LICENSE for details.
- *
- * $Id: odr_cons.c,v 1.8 2007-01-03 08:42:15 adam Exp $
- *
  */
 
 /**
@@ -21,7 +18,7 @@
 
 void odr_setlenlen(ODR o, int len)
 {
-    o->lenlen = len;
+    o->op->lenlen = len;
 }
 
 int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
@@ -29,17 +26,18 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
 {
     int res;
     int cons = 1;
-    int lenlen = o->lenlen;
+    int lenlen = o->op->lenlen;
 
     if (o->error)
         return 0;
-    o->lenlen = 1; /* reset lenlen */
-    if (o->t_class < 0)
+    o->op->lenlen = 1; /* reset lenlen */
+    if (o->op->t_class < 0)
     {
-        o->t_class = zclass;
-        o->t_tag = tag;
+        o->op->t_class = zclass;
+        o->op->t_tag = tag;
     }
-    if ((res = ber_tag(o, xxp, o->t_class, o->t_tag, &cons, 1, name)) < 0)
+    res = ber_tag(o, xxp, o->op->t_class, o->op->t_tag, &cons, 1, name);
+    if (res < 0)
         return 0;
     if (!res || !cons)
         return 0;
@@ -85,12 +83,12 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
         o->op->stack_top = o->op->stack_first;
         assert(o->op->stack_top->prev == 0);
     }
-    o->op->stack_top->lenb = o->bp;
+    o->op->stack_top->lenb = o->op->bp;
     o->op->stack_top->len_offset = odr_tell(o);
     o->op->stack_top->name = name ? name : "?";
     if (o->direction == ODR_ENCODE)
     {
-        static unsigned char dummy[sizeof(int)+1];
+        static char dummy[sizeof(int)+1];
 
         o->op->stack_top->lenlen = lenlen;
 
@@ -102,7 +100,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
     }
     else if (o->direction == ODR_DECODE)
     {
-        if ((res = ber_declen(o->bp, &o->op->stack_top->len,
+        if ((res = ber_declen(o->op->bp, &o->op->stack_top->len,
                               odr_max(o))) < 0)
         {
             odr_seterror(o, OOTHER, 31);
@@ -110,7 +108,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
             return 0;
         }
         o->op->stack_top->lenlen = res;
-        o->bp += res;
+        o->op->bp += res;
         if (o->op->stack_top->len > odr_max(o))
         {
             odr_seterror(o, OOTHER, 32);
@@ -122,7 +120,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
     {
         odr_prname(o, name);
         odr_printf(o, "{\n");
-        o->indent++;
+        o->op->indent++;
     }
     else
     {
@@ -130,7 +128,7 @@ int odr_constructed_begin(ODR o, void *xxp, int zclass, int tag,
         ODR_STACK_POP(o);
         return 0;
     }
-    o->op->stack_top->base = o->bp;
+    o->op->stack_top->base = o->op->bp;
     o->op->stack_top->base_offset = odr_tell(o);
     return 1;
 }
@@ -142,9 +140,9 @@ int odr_constructed_more(ODR o)
     if (ODR_STACK_EMPTY(o))
         return 0;
     if (o->op->stack_top->len >= 0)
-        return o->bp - o->op->stack_top->base < o->op->stack_top->len;
+        return o->op->bp - o->op->stack_top->base < o->op->stack_top->len;
     else
-        return (!(*o->bp == 0 && *(o->bp + 1) == 0));
+        return (!(*o->op->bp == 0 && *(o->op->bp + 1) == 0));
 }
 
 int odr_constructed_end(ODR o)
@@ -164,7 +162,7 @@ int odr_constructed_end(ODR o)
     case ODR_DECODE:
         if (o->op->stack_top->len < 0)
         {
-            if (*o->bp++ == 0 && *(o->bp++) == 0)
+            if (*o->op->bp++ == 0 && *(o->op->bp++) == 0)
             {
                 ODR_STACK_POP(o);
                 return 1;
@@ -175,7 +173,7 @@ int odr_constructed_end(ODR o)
                 return 0;
             }
         }
-        else if (o->bp - o->op->stack_top->base !=
+        else if (o->op->bp - o->op->stack_top->base !=
                  o->op->stack_top->len)
         {
             odr_seterror(o, OCONLEN, 36);
@@ -202,7 +200,7 @@ int odr_constructed_end(ODR o)
         return 1;
     case ODR_PRINT:
         ODR_STACK_POP(o);
-        o->indent--;
+        o->op->indent--;
         odr_prname(o, 0);
         odr_printf(o, "}\n");
         return 1;
@@ -214,6 +212,7 @@ int odr_constructed_end(ODR o)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab