From 5b7d1b7785d365515b0a9b5cfcb88d6b0e13ec51 Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Thu, 22 Mar 2012 20:30:56 +0100 Subject: [PATCH] scansbr: Minor refactoring and some comments. --- uip/scansbr.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/uip/scansbr.c b/uip/scansbr.c index b15c908..9f6306d 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -30,9 +30,7 @@ /* ** Buffer size for content part of header fields. We want this ** to be large enough so that we don't do a lot of extra FLDPLUS -** calls on m_getfld but small enough so that we don't snarf -** the entire message body when we're only going to display 30 -** characters of it. +** calls on m_getfld. */ #define SBUFSIZ 512 @@ -67,6 +65,7 @@ int scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, int unseen) { + static int slwidth; int i, compnum, state; unsigned char *cp, *tmpbuf; char **nxtbuf; @@ -75,7 +74,6 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, char *scnmsg = NULL; FILE *scnout = NULL; char name[NAMESZ]; - static int slwidth; char returnpath[BUFSIZ]; char deliverydate[BUFSIZ]; int incing = (outnum > 0); @@ -91,7 +89,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, } dat[3] = slwidth = width; scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * - (slwidth + 2) ); + (slwidth + 2)); /* probably for \n and \0 */ if (incing) umask(~m_gmprot()); @@ -101,13 +99,16 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, FINDCOMP(datecomp, "date"); nxtbuf = compbuffers = (char **) calloc((size_t) ncomps, sizeof(char *)); - if (nxtbuf == NULL) + if (!nxtbuf) adios(NULL, "unable to allocate component buffers"); used_buf = (struct comp **) calloc((size_t) (ncomps+1), - sizeof(struct comp *)); - if (used_buf == NULL) + sizeof(struct comp *)); + if (!used_buf) adios(NULL, "unable to allocate component buffer stack"); - used_buf += ncomps+1; *--used_buf = 0; + /* NULL-terminate array */ + used_buf += ncomps; + *used_buf = NULL; + /* allocate space for the items */ for (i = ncomps; i--; ) *nxtbuf++ = mh_xmalloc(SBUFSIZ); } @@ -139,7 +140,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, scnmsg = m_name(outnum); if (*scnmsg == '?') /* msg num out of range */ return SCNNUM; - if ((scnout = fopen(scnmsg, "w")) == NULL) + if (!(scnout = fopen(scnmsg, "w"))) adios(scnmsg, "unable to write"); /* ** Add the Return-Path and Delivery-Date @@ -288,9 +289,9 @@ finished: dat[2] = st.st_size; if (datecomp) { if (!datecomp->c_text) { - if (datecomp->c_tws == NULL) + if (!datecomp->c_tws) datecomp->c_tws = (struct tws *) calloc((size_t) 1, sizeof(*datecomp->c_tws)); - if (datecomp->c_tws == NULL) + if (!datecomp->c_tws) adios(NULL, "unable to allocate tws buffer"); *datecomp->c_tws = *dlocaltime((time_t *) &st.st_mtime); datecomp->c_flags |= CF_DATEFAB|CF_TRUE; -- 1.7.10.4