From a87df3543d3bc128ba4079d1f95638476ba5ca50 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Thu, 26 Nov 2015 23:24:18 +0100 Subject: [PATCH] add free_field as standard for struct field this is a easy way to initializ a struct field. ``{{0}}'' can lead to bugs, because NULL is not necesary ``((void *)0)'' --- h/mh.h | 2 ++ sbr/m_getfld2.c | 14 ++++++-------- sbr/readconfig.c | 2 +- sbr/seq_read.c | 2 +- uip/distsbr.c | 4 ++-- uip/mhbuild.c | 2 +- uip/mhl.c | 2 +- uip/mhparse.c | 2 +- uip/new.c | 2 +- uip/pick.c | 2 +- uip/prompter.c | 2 +- uip/rcvdist.c | 2 +- uip/repl.c | 2 +- uip/scansbr.c | 2 +- uip/slocal.c | 2 +- uip/sortm.c | 2 +- uip/spost.c | 2 +- uip/whom.c | 2 +- 18 files changed, 25 insertions(+), 25 deletions(-) diff --git a/h/mh.h b/h/mh.h index 8f6fad1..481f2f1 100644 --- a/h/mh.h +++ b/h/mh.h @@ -212,6 +212,8 @@ struct field { size_t alloclen; }; +extern struct field free_field; + /* m_getfld2() states */ enum state { LENERR2 = -2, /* Line too long */ diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index cd1c6be..6545d0f 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -26,6 +26,8 @@ static enum threestate is_falted(FILE *); static size_t copyname(char *, char *); static bool is_separator(char *); +struct field free_field = { "\0", 0, NULL, 0, 0 }; + /* ** FLD2: We read a (complete) header field @@ -55,7 +57,7 @@ m_getfld2(enum state s, struct field *f, FILE *msg) nchars = getline(&tmpline, &len, msg); if (nchars < 1) { free(f->value); - *f = (struct field) { "\0", 0, NULL, 0, 0 }; + *f = free_field; if (feof(msg)) { return FILEEOF2; } else { @@ -130,15 +132,12 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return ret; case BODY2: - *f->name = '\0'; - f->namelen = 0; + free(f->value); + *f = free_field; nchars = getline(&tmpline, &len, msg); if (nchars < 1) { - free(f->value); - f->value = NULL; - f->valuelen = 0; - f->alloclen = 0; + free(tmpline); if (feof(msg)) { return FILEEOF2; } else { @@ -150,7 +149,6 @@ m_getfld2(enum state s, struct field *f, FILE *msg) ret = LENERR2; } - free(f->value); f->value = tmpline; f->valuelen = nchars; f->alloclen = len; diff --git a/sbr/readconfig.c b/sbr/readconfig.c index ccdf867..645a9ef 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -37,7 +37,7 @@ void readconfig(struct node **npp, FILE *ib, char *file, int ctx) { enum state state; - struct field f = {{0}}; + struct field f = free_field; struct node *np; struct procstr *ps; diff --git a/sbr/seq_read.c b/sbr/seq_read.c index 1929b26..68351ac 100644 --- a/sbr/seq_read.c +++ b/sbr/seq_read.c @@ -56,7 +56,7 @@ static void seq_public(struct msgs *mp) { enum state state; - struct field f = {{0}}; + struct field f = free_field; char seqfile[PATH_MAX]; FILE *fp; diff --git a/uip/distsbr.c b/uip/distsbr.c index 9c20fda..21b42a5 100644 --- a/uip/distsbr.c +++ b/uip/distsbr.c @@ -25,7 +25,7 @@ int distout(char *drft, char *msgnam, char *backup) { enum state state; - struct field f = {{0}}; + struct field f = free_field; unsigned char *dp; int resent = 0; FILE *ifp, *ofp; @@ -123,7 +123,7 @@ static int ready_msg(char *msgnam) { enum state state; - struct field f = {{0}}; + struct field f = free_field; char tmpfil[BUFSIZ]; int out; FILE *ifp, *ofp; diff --git a/uip/mhbuild.c b/uip/mhbuild.c index ec5623a..c4b1c60 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -313,7 +313,7 @@ static CT build_mime(char *infile) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int compnum; char buf[BUFSIZ]; char *cp, *np, *vp; diff --git a/uip/mhl.c b/uip/mhl.c index 8becba9..20f5d31 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -599,7 +599,7 @@ static void mhlfile(FILE *fp, char *mname, int ofilen, int ofilec) { enum state state; - struct field f = {{0}}; + struct field f = free_field; struct mcomp *c1, *c2, *c3; char **ip; diff --git a/uip/mhparse.c b/uip/mhparse.c index 257bc66..04333f4 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -232,7 +232,7 @@ static CT get_content(FILE *in, char *file, int toplevel) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int compnum; CT ct; HF hp; diff --git a/uip/new.c b/uip/new.c index a2be29b..60bb806 100644 --- a/uip/new.c +++ b/uip/new.c @@ -96,7 +96,7 @@ static char * get_msgnums(char *folder, char *sequences[]) { enum state state; - struct field f = {{0}}; + struct field f = free_field; char *seqfile = concat(toabsdir(folder), "/", mh_seq, (void *)NULL); FILE *fp = fopen(seqfile, "r"); char *msgnums = NULL, *this_msgnums, *old_msgnums; diff --git a/uip/pick.c b/uip/pick.c index 993527b..03af15a 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -1242,7 +1242,7 @@ TWSaction(params) plist { enum state state; - struct field f = {{0}}; + struct field f = free_field; char *bp; struct tws *tw; diff --git a/uip/prompter.c b/uip/prompter.c index 24f2d9f..21ec5ce 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -57,7 +57,7 @@ main(int argc, char **argv) int fdi, fdo, i; char *cp, *drft = NULL; enum state state; - struct field f = {{0}}; + struct field f = free_field; char buffer[BUFSIZ], tmpfil[BUFSIZ]; char **arguments, **argp; FILE *in, *out; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 8292a20..b54bc39 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -154,7 +154,7 @@ rcvdistout(FILE *inb, char *form, char *addrs) { int char_read = 0, format_len, i; enum state state; - struct field f = {{0}}; + struct field f = free_field; char **ap; char *cp, *scanl; struct comp *cptr; diff --git a/uip/repl.c b/uip/repl.c index d71f27b..bbc3cfe 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -378,7 +378,7 @@ replout(FILE *inb, char *drft, struct msgs *mp, int mime, char *form, char *filter) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int i; struct comp *cptr; char **ap; diff --git a/uip/scansbr.c b/uip/scansbr.c index 50b250e..8281c7b 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -50,7 +50,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, static int slwidth; int compnum, i; enum state state; - struct field f = {{0}}; + struct field f = free_field; char *cp; struct comp *cptr; char *scnmsg = NULL; diff --git a/uip/slocal.c b/uip/slocal.c index c3b45e8..3b5007d 100644 --- a/uip/slocal.c +++ b/uip/slocal.c @@ -725,7 +725,7 @@ static int parse(int fd) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int i, fd1; char *cp, *dp, *lp; struct pair *p, *q; diff --git a/uip/sortm.c b/uip/sortm.c index 61953e1..6d45d35 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -321,7 +321,7 @@ static int get_fields(char *datesw, int msg, struct smsg *smsg) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int compnum; char *msgnam; struct tws *tw; diff --git a/uip/spost.c b/uip/spost.c index 04479a1..b8ae562 100644 --- a/uip/spost.c +++ b/uip/spost.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int compnum; char *cp, *msg = NULL, **argp, **arguments; char **sargv, buf[BUFSIZ]; diff --git a/uip/whom.c b/uip/whom.c index a72c84f..c4e7e8f 100644 --- a/uip/whom.c +++ b/uip/whom.c @@ -204,7 +204,7 @@ static int process(char *file) { enum state state; - struct field f = {{0}}; + struct field f = free_field; int compnum; FILE *in; -- 1.7.10.4