add free_field as standard for struct field
authorPhilipp Takacs <philipp@bureaucracy.de>
Thu, 26 Nov 2015 22:24:18 +0000 (23:24 +0100)
committerPhilipp Takacs <philipp@bureaucracy.de>
Fri, 27 Nov 2015 01:01:17 +0000 (02:01 +0100)
this is a easy way to initializ a struct field. ``{{0}}''
can lead to bugs, because NULL is not necesary ``((void *)0)''

18 files changed:
h/mh.h
sbr/m_getfld2.c
sbr/readconfig.c
sbr/seq_read.c
uip/distsbr.c
uip/mhbuild.c
uip/mhl.c
uip/mhparse.c
uip/new.c
uip/pick.c
uip/prompter.c
uip/rcvdist.c
uip/repl.c
uip/scansbr.c
uip/slocal.c
uip/sortm.c
uip/spost.c
uip/whom.c

diff --git a/h/mh.h b/h/mh.h
index 8f6fad1..481f2f1 100644 (file)
--- a/h/mh.h
+++ b/h/mh.h
@@ -212,6 +212,8 @@ struct field {
        size_t alloclen;
 };
 
        size_t alloclen;
 };
 
+extern struct field free_field;
+
 /* m_getfld2() states */
 enum state {
        LENERR2 = -2,      /* Line too long */
 /* m_getfld2() states */
 enum state {
        LENERR2 = -2,      /* Line too long */
index cd1c6be..6545d0f 100644 (file)
@@ -26,6 +26,8 @@ static enum threestate is_falted(FILE *);
 static size_t copyname(char *, char *);
 static bool is_separator(char *);
 
 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
 
 /*
 ** 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);
                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 {
                        if (feof(msg)) {
                                return FILEEOF2;
                        } else {
@@ -130,15 +132,12 @@ m_getfld2(enum state s, struct field *f, FILE *msg)
                return ret;
 
        case BODY2:
                return ret;
 
        case BODY2:
-               *f->name = '\0';
-               f->namelen = 0;
+               free(f->value);
+               *f = free_field;
 
                nchars = getline(&tmpline, &len, msg);
                if (nchars < 1) {
 
                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 {
                        if (feof(msg)) {
                                return FILEEOF2;
                        } else {
@@ -150,7 +149,6 @@ m_getfld2(enum state s, struct field *f, FILE *msg)
                        ret = LENERR2;
                }
 
                        ret = LENERR2;
                }
 
-               free(f->value);
                f->value = tmpline;
                f->valuelen = nchars;
                f->alloclen = len;
                f->value = tmpline;
                f->valuelen = nchars;
                f->alloclen = len;
index ccdf867..645a9ef 100644 (file)
@@ -37,7 +37,7 @@ void
 readconfig(struct node **npp, FILE *ib, char *file, int ctx)
 {
        enum state state;
 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;
 
        struct node *np;
        struct procstr *ps;
 
index 1929b26..68351ac 100644 (file)
@@ -56,7 +56,7 @@ static void
 seq_public(struct msgs *mp)
 {
        enum state state;
 seq_public(struct msgs *mp)
 {
        enum state state;
-       struct field f = {{0}};
+       struct field f = free_field;
        char seqfile[PATH_MAX];
        FILE *fp;
 
        char seqfile[PATH_MAX];
        FILE *fp;
 
index 9c20fda..21b42a5 100644 (file)
@@ -25,7 +25,7 @@ int
 distout(char *drft, char *msgnam, char *backup)
 {
        enum state state;
 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;
        unsigned char *dp;
        int resent = 0;
        FILE *ifp, *ofp;
@@ -123,7 +123,7 @@ static int
 ready_msg(char *msgnam)
 {
        enum state state;
 ready_msg(char *msgnam)
 {
        enum state state;
-       struct field f = {{0}};
+       struct field f = free_field;
        char tmpfil[BUFSIZ];
        int out;
        FILE *ifp, *ofp;
        char tmpfil[BUFSIZ];
        int out;
        FILE *ifp, *ofp;
index ec5623a..c4b1c60 100644 (file)
@@ -313,7 +313,7 @@ static CT
 build_mime(char *infile)
 {
        enum state state;
 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;
        int compnum;
        char buf[BUFSIZ];
        char *cp, *np, *vp;
index 8becba9..20f5d31 100644 (file)
--- 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;
 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;
 
        struct mcomp *c1, *c2, *c3;
        char **ip;
 
index 257bc66..04333f4 100644 (file)
@@ -232,7 +232,7 @@ static CT
 get_content(FILE *in, char *file, int toplevel)
 {
        enum state state;
 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;
        int compnum;
        CT ct;
        HF hp;
index a2be29b..60bb806 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -96,7 +96,7 @@ static char *
 get_msgnums(char *folder, char *sequences[])
 {
        enum state state;
 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;
        char *seqfile = concat(toabsdir(folder), "/", mh_seq, (void *)NULL);
        FILE *fp = fopen(seqfile, "r");
        char *msgnums = NULL, *this_msgnums, *old_msgnums;
index 993527b..03af15a 100644 (file)
@@ -1242,7 +1242,7 @@ TWSaction(params)
 plist
 {
        enum state state;
 plist
 {
        enum state state;
-       struct field f = {{0}};
+       struct field f = free_field;
        char *bp;
        struct tws *tw;
 
        char *bp;
        struct tws *tw;
 
index 24f2d9f..21ec5ce 100644 (file)
@@ -57,7 +57,7 @@ main(int argc, char **argv)
        int fdi, fdo, i;
        char *cp, *drft = NULL;
        enum state state;
        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;
        char buffer[BUFSIZ], tmpfil[BUFSIZ];
        char **arguments, **argp;
        FILE *in, *out;
index 8292a20..b54bc39 100644 (file)
@@ -154,7 +154,7 @@ rcvdistout(FILE *inb, char *form, char *addrs)
 {
        int char_read = 0, format_len, i;
        enum state state;
 {
        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;
        char **ap;
        char *cp, *scanl;
        struct comp *cptr;
index d71f27b..bbc3cfe 100644 (file)
@@ -378,7 +378,7 @@ replout(FILE *inb, char *drft, struct msgs *mp,
        int mime, char *form, char *filter)
 {
        enum state state;
        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;
        int i;
        struct comp *cptr;
        char **ap;
index 50b250e..8281c7b 100644 (file)
@@ -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;
        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;
        char *cp;
        struct comp *cptr;
        char *scnmsg = NULL;
index c3b45e8..3b5007d 100644 (file)
@@ -725,7 +725,7 @@ static int
 parse(int fd)
 {
        enum state state;
 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;
        int i, fd1;
        char *cp, *dp, *lp;
        struct pair *p, *q;
index 61953e1..6d45d35 100644 (file)
@@ -321,7 +321,7 @@ static int
 get_fields(char *datesw, int msg, struct smsg *smsg)
 {
        enum state state;
 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;
        int compnum;
        char *msgnam;
        struct tws *tw;
index 04479a1..b8ae562 100644 (file)
@@ -144,7 +144,7 @@ int
 main(int argc, char **argv)
 {
        enum state state;
 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];
        int compnum;
        char *cp, *msg = NULL, **argp, **arguments;
        char **sargv, buf[BUFSIZ];
index a72c84f..c4e7e8f 100644 (file)
@@ -204,7 +204,7 @@ static int
 process(char *file)
 {
        enum state state;
 process(char *file)
 {
        enum state state;
-       struct field f = {{0}};
+       struct field f = free_field;
        int compnum;
        FILE *in;
 
        int compnum;
        FILE *in;