Fixed possible buf in proto.c
[yaz-moved-to-github.git] / odr / ber_null.c
index b650c87..2fbaf6d 100644 (file)
@@ -4,7 +4,13 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_null.c,v $
- * Revision 1.1  1995-02-02 16:21:52  quinn
+ * Revision 1.3  1995-03-08 12:12:09  quinn
+ * Added better error checking.
+ *
+ * Revision 1.2  1995/02/09  15:51:46  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/02  16:21:52  quinn
  * First kick.
  *
  */
@@ -19,17 +25,29 @@ int ber_null(ODR o, int *val)
     switch (o->direction)
     {
        case ODR_ENCODE:
+           if (!o->left)
+           {
+               o->error = OSPACE;
+               return 0;
+           }
            *(o->bp++) = 0X00;
            o->left--;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[NULL]\n");
+#endif
            return 1;
        case ODR_DECODE:
            if (*(o->bp++) != 0X00)
+           {
+               o->error = OPROTO;
                return 0;
+           }
            o->left--;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[NULL]\n");
+#endif
            return 1;
        case ODR_PRINT: return 1;
-       default: return 0;
+       default: o->error = OOTHER; return 0;
     }
 }