From 393cf1d9803c3dfda0fbb8add9bc5cb9b1f6f07b Mon Sep 17 00:00:00 2001 Message-Id: <393cf1d9803c3dfda0fbb8add9bc5cb9b1f6f07b.1716553427.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sat, 20 Jan 2001 12:06:01 +0000 Subject: [PATCH] Define flags with macros, to ensure unsignedness. Organization: Straylight/Edgeware From: mdw --- crc-mktab.c | 13 +++++++------ dputf.c | 27 +++++++++++++++++---------- lbuf.h | 11 ++++++----- pkbuf.h | 9 +++++---- url.h | 9 +++++---- 5 files changed, 40 insertions(+), 29 deletions(-) diff --git a/crc-mktab.c b/crc-mktab.c index def5361..a3ba430 100644 --- a/crc-mktab.c +++ b/crc-mktab.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: crc-mktab.c,v 1.2 2000/10/08 11:07:21 mdw Exp $ + * $Id: crc-mktab.c,v 1.3 2001/01/20 12:06:01 mdw Exp $ * * Build CRC tables * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: crc-mktab.c,v $ + * Revision 1.3 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * * Revision 1.2 2000/10/08 11:07:21 mdw * With no arguments, give an error rather than spewing a big table at the * user. @@ -66,11 +69,9 @@ static const char *type = 0; static const char *inc = 0; static FILE *fp; -enum { - f_bogus = 1, - f_ctab = 2, - f_reverse = 4 -}; +#define f_bogus 1u +#define f_ctab 2u +#define f_reverse 4u #define BSCOL 72 diff --git a/dputf.c b/dputf.c index d78851f..5df210c 100644 --- a/dputf.c +++ b/dputf.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: dputf.c,v 1.2 2000/08/15 21:26:45 mdw Exp $ + * $Id: dputf.c,v 1.3 2001/01/20 12:06:01 mdw Exp $ * * `printf'-style formatting for dynamic strings * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: dputf.c,v $ + * Revision 1.3 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * * Revision 1.2 2000/08/15 21:26:45 mdw * (dstr_vputf): Don't try calling @va_arg@ on things @char@-sized. * @@ -84,13 +87,11 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) unsigned f; int wd, prec; - enum { - f_short = 1, - f_long = 2, - f_Long = 4, - f_wd = 8, - f_prec = 16 - }; +#define f_short 1u +#define f_long 2u +#define f_Long 4u +#define f_wd 8u +#define f_prec 16u /* --- Most stuff gets passed on through --- */ @@ -198,9 +199,9 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) if (mx > sz) sz = mx; } - if ((f & f_prec) == 0) + if (!(f & f_prec)) prec = 6; - if ((f & f_prec)) + else sz += prec + 16; if ((f & f_wd) && wd + 1 > sz) sz = wd + 1; @@ -270,6 +271,12 @@ int dstr_vputf(dstr *d, const char *p, va_list ap) formatted: DRESET(&dd); q = ++p; + +#undef f_short +#undef f_long +#undef f_Long +#undef f_wd +#undef f_prec } DPUTM(d, q, p - q); diff --git a/lbuf.h b/lbuf.h index 3f25dac..9f290b8 100644 --- a/lbuf.h +++ b/lbuf.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: lbuf.h,v 1.4 2000/06/17 10:38:14 mdw Exp $ + * $Id: lbuf.h,v 1.5 2001/01/20 12:06:01 mdw Exp $ * * Block-to-line buffering * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: lbuf.h,v $ + * Revision 1.5 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * * Revision 1.4 2000/06/17 10:38:14 mdw * Add support for variable buffer sizes. * @@ -119,10 +122,8 @@ typedef struct lbuf { char *buf; /* The actual buffer */ } lbuf; -enum { - LBUF_CR = 1, /* Read a carriage return */ - LBUF_ENABLE = 2 /* Buffer is currently enabled */ -}; +#define LBUF_CR 1u /* Read a carriage return */ +#define LBUF_ENABLE 2u /* Buffer is currently enabled */ /*----- Functions provided ------------------------------------------------*/ diff --git a/pkbuf.h b/pkbuf.h index e6bbec3..d98d826 100644 --- a/pkbuf.h +++ b/pkbuf.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: pkbuf.h,v 1.1 2000/06/17 10:39:19 mdw Exp $ + * $Id: pkbuf.h,v 1.2 2001/01/20 12:06:01 mdw Exp $ * * Simple packet buffering * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: pkbuf.h,v $ + * Revision 1.2 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * * Revision 1.1 2000/06/17 10:39:19 mdw * Experimental new support for packet buffering. * @@ -69,9 +72,7 @@ typedef struct pkbuf { octet *buf; /* Actual buffer space */ } pkbuf; -enum { - PKBUF_ENABLE = 1 /* Buffer is currently enabled */ -}; +#define PKBUF_ENABLE 1u /* Buffer is currently enabled */ /*----- Functions provided ------------------------------------------------*/ diff --git a/url.h b/url.h index 55e443d..90b649a 100644 --- a/url.h +++ b/url.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: url.h,v 1.2 1999/12/10 23:42:04 mdw Exp $ + * $Id: url.h,v 1.3 2001/01/20 12:06:01 mdw Exp $ * * Parsing and construction of url-encoded name/value pairs * @@ -30,6 +30,9 @@ /*----- Revision history --------------------------------------------------* * * $Log: url.h,v $ + * Revision 1.3 2001/01/20 12:06:01 mdw + * Define flags with macros, to ensure unsignedness. + * * Revision 1.2 1999/12/10 23:42:04 mdw * Change header file guard names. * @@ -57,9 +60,7 @@ typedef struct url_ectx { unsigned f; } url_ectx; -enum { - URLF_SEP = 1 -}; +#define URLF_SEP 1u typedef struct url_dctx { const char *p; -- [mdw]