From: mdw Date: Sat, 3 Feb 2001 16:23:33 +0000 (+0000) Subject: Bug fix: handle a disable during a close-induced flush without dumping X-Git-Tag: 2.0.4~109 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/commitdiff_plain/3fd896a441c904c3f3608dba41d5e1db84fad776 Bug fix: handle a disable during a close-induced flush without dumping core. --- diff --git a/lbuf.c b/lbuf.c index 9c0ec22..8b93076 100644 --- 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 * @@ -30,6 +30,10 @@ /*----- 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 9f290b8..fb04b5f 100644 --- 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 * @@ -30,6 +30,10 @@ /*----- 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 ce39d94..629f531 100644 --- 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 * @@ -30,6 +30,10 @@ /*----- 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 d98d826..00c437b 100644 --- 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 * @@ -30,6 +30,10 @@ /*----- 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 ------------------------------------------------*/