chiark / gitweb /
Bug fix: handle a disable during a close-induced flush without dumping
authormdw <mdw>
Sat, 3 Feb 2001 16:23:33 +0000 (16:23 +0000)
committermdw <mdw>
Sat, 3 Feb 2001 16:23:33 +0000 (16:23 +0000)
core.

lbuf.c
lbuf.h
pkbuf.c
pkbuf.h

diff --git a/lbuf.c b/lbuf.c
index 9c0ec229d96c8b20afff38a6ae185ca498e219ea..8b930763d34016a31ead58ad95a39b1fd2de318f 100644 (file)
--- a/lbuf.c
+++ b/lbuf.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: lbuf.c,v 1.4 2000/06/17 10:38:14 mdw Exp $
+ * $Id: lbuf.c,v 1.5 2001/02/03 16:23:33 mdw Exp $
  *
  * Block-to-line buffering
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: lbuf.c,v $
+ * Revision 1.5  2001/02/03 16:23:33  mdw
+ * Bug fix: handle a disable during a close-induced flush without dumping
+ * core.
+ *
  * Revision 1.4  2000/06/17 10:38:14  mdw
  * Add support for variable buffer sizes.
  *
@@ -87,6 +91,11 @@ void lbuf_flush(lbuf *b, char *p, size_t len)
   char *base;                          /* Base address of current line */
   int cr;                              /* Carriage return state */
 
+  if (b->f & LBUF_CLOSE) {
+    b->func(0, b->p);
+    return;
+  }
+
   /* --- Initialize variables as necessary --- */
 
   if (!p) {
@@ -192,6 +201,7 @@ void lbuf_close(lbuf *b)
     x_free(b->a, b->buf);
     b->buf = 0;
   }
+  b->f |= LBUF_CLOSE;
   if (b->f & LBUF_ENABLE)
     b->func(0, b->p);
 }
diff --git a/lbuf.h b/lbuf.h
index 9f290b808538d05610cd5f70175b7cd12de9a5cf..fb04b5f83630ae5ddff09b3410934dc95518e0db 100644 (file)
--- a/lbuf.h
+++ b/lbuf.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: lbuf.h,v 1.5 2001/01/20 12:06:01 mdw Exp $
+ * $Id: lbuf.h,v 1.6 2001/02/03 16:23:33 mdw Exp $
  *
  * Block-to-line buffering
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: lbuf.h,v $
+ * Revision 1.6  2001/02/03 16:23:33  mdw
+ * Bug fix: handle a disable during a close-induced flush without dumping
+ * core.
+ *
  * Revision 1.5  2001/01/20 12:06:01  mdw
  * Define flags with macros, to ensure unsignedness.
  *
@@ -124,6 +128,7 @@ typedef struct lbuf {
 
 #define LBUF_CR 1u                     /* Read a carriage return */
 #define LBUF_ENABLE 2u                 /* Buffer is currently enabled */
+#define LBUF_CLOSE 4u                  /* Buffer is now closed */
 
 /*----- Functions provided ------------------------------------------------*/
 
diff --git a/pkbuf.c b/pkbuf.c
index ce39d943aa3b66e91a88f1d847114e2131186cca..629f53140ace1cf59ee3d95f36c3df24965e2c1d 100644 (file)
--- a/pkbuf.c
+++ b/pkbuf.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pkbuf.c,v 1.3 2000/07/16 18:55:45 mdw Exp $
+ * $Id: pkbuf.c,v 1.4 2001/02/03 16:23:33 mdw Exp $
  *
  * Simple packet buffering
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pkbuf.c,v $
+ * Revision 1.4  2001/02/03 16:23:33  mdw
+ * Bug fix: handle a disable during a close-induced flush without dumping
+ * core.
+ *
  * Revision 1.3  2000/07/16 18:55:45  mdw
  * Remove some stray debugging code.
  *
@@ -81,6 +85,11 @@ void pkbuf_flush(pkbuf *pk, octet *p, size_t len)
   size_t l;
   size_t keep;
 
+  if (pk->f & PKBUF_CLOSE) {
+    pk->func(0, 0, pk, 0, pk->p);
+    return;
+  }
+
   /* --- Initialize variables as necessary --- */
 
   if (!p) {
@@ -135,6 +144,7 @@ void pkbuf_close(pkbuf *pk)
     x_free(pk->a, pk->buf);
     pk->buf = 0;
   }
+  pk->f |= PKBUF_CLOSE;
   if (pk->f & PKBUF_ENABLE)
     pk->func(0, 0, pk, 0, pk->p);
 }
diff --git a/pkbuf.h b/pkbuf.h
index d98d826555a72e1e5abc93d30e491ba72f7b299b..00c437ba45d3418593da051a79064bf78d823b8b 100644 (file)
--- a/pkbuf.h
+++ b/pkbuf.h
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: pkbuf.h,v 1.2 2001/01/20 12:06:01 mdw Exp $
+ * $Id: pkbuf.h,v 1.3 2001/02/03 16:23:33 mdw Exp $
  *
  * Simple packet buffering
  *
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: pkbuf.h,v $
+ * Revision 1.3  2001/02/03 16:23:33  mdw
+ * Bug fix: handle a disable during a close-induced flush without dumping
+ * core.
+ *
  * Revision 1.2  2001/01/20 12:06:01  mdw
  * Define flags with macros, to ensure unsignedness.
  *
@@ -73,6 +77,7 @@ typedef struct pkbuf {
 } pkbuf;
 
 #define PKBUF_ENABLE 1u                        /* Buffer is currently enabled */
+#define PKBUF_CLOSE 2u                 /* Buffer is now closed */
 
 /*----- Functions provided ------------------------------------------------*/