No error-checking for error-checking alloc functions
[mmh] / uip / mhbuild.c
index 1fdedb6..b8e9f93 100644 (file)
@@ -312,8 +312,10 @@ unlink_done()
 static CT
 build_mime(char *infile)
 {
-       int compnum, state;
-       char buf[BUFSIZ], name[NAMESZ];
+       enum state state;
+       struct field f = {{0}};
+       int compnum;
+       char buf[BUFSIZ];
        char *cp, *np, *vp;
        struct multipart *m;
        struct part **pp;
@@ -324,14 +326,14 @@ build_mime(char *infile)
        umask(~m_gmprot());
 
        /* open the composition draft */
-       if ((in = fopen(infile, "r")) == NULL)
+       if ((in = fopen(infile, "r")) == NULL) {
                adios(EX_IOERR, infile, "unable to open for reading");
+       }
 
        /*
        ** Allocate space for primary (outside) content
        */
-       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
-               adios(EX_OSERR, NULL, "out of memory");
+       ct = (CT) mh_xcalloc(1, sizeof(*ct));
 
        /*
        ** Allocate structure for handling decoded content
@@ -345,63 +347,45 @@ build_mime(char *infile)
        ** draft into the linked list of header fields for
        ** the new MIME message.
        */
-       for (compnum = 1, state = FLD;;) {
-               switch (state = m_getfld(state, name, buf, sizeof(buf), in)) {
-               case FLD:
-               case FLDPLUS:
-               case FLDEOF:
+       for (compnum = 1, state = FLD2;;) {
+               switch (state = m_getfld2(state, &f, in)) {
+               case FLD2:
                        compnum++;
 
                        /* abort if draft has Mime-Version header field */
-                       if (!mh_strcasecmp(name, VRSN_FIELD))
+                       if (!mh_strcasecmp(f.name, VRSN_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+                       }
 
                        /*
                        ** abort if draft has Content-Transfer-Encoding
                        ** header field
                        */
-                       if (!mh_strcasecmp(name, ENCODING_FIELD))
+                       if (!mh_strcasecmp(f.name, ENCODING_FIELD)) {
                                adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
+                       }
 
                        /* ignore any Content-Type fields in the header */
-                       if (!mh_strcasecmp(name, TYPE_FIELD)) {
-                               while (state == FLDPLUS)
-                                       state = m_getfld(state, name, buf,
-                                                       sizeof(buf), in);
-                               goto finish_field;
+                       if (!mh_strcasecmp(f.name, TYPE_FIELD)) {
+                               continue;
                        }
 
-                       /* get copies of the buffers */
-                       np = getcpy(name);
-                       vp = getcpy(buf);
-
-                       /* if necessary, get rest of field */
-                       while (state == FLDPLUS) {
-                               state = m_getfld(state, name, buf,
-                                               sizeof(buf), in);
-                               vp = add(buf, vp);  /* add to prev value */
-                       }
+                       /* add the header data to the list */
+                       add_header(ct, getcpy(f.name), getcpy(f.value));
 
-                       /* Now add the header data to the list */
-                       add_header(ct, np, vp);
+                       continue;
 
-finish_field:
-                       /* if this wasn't the last hdr field, then continue */
-                       if (state != FLDEOF)
-                               continue;
-                       /* else fall... */
+               case BODY2:
+                       fseek(in, (long) (-strlen(f.value)), SEEK_CUR);
+                       break;
 
-               case FILEEOF:
+               case FILEEOF2:
                        adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
                        /* NOTREACHED */
 
-               case BODY:
-               case BODYEOF:
-                       fseek(in, (long) (-strlen(buf)), SEEK_CUR);
-                       break;
-
-               case LENERR:
-               case FMTERR:
+               case LENERR2:
+               case FMTERR2:
+               case ERR2:
                        adios(EX_CONFIG, NULL, "message format error in component #%d",
                                        compnum);
 
@@ -441,8 +425,7 @@ finish_field:
        ct->c_subtype = MULTI_MIXED;
        ct->c_file = getcpy(infile);
 
-       if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
-               adios(EX_OSERR, NULL, "out of memory");
+       m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
        ct->c_ctparams = (void *) m;
        pp = &m->mp_parts;
 
@@ -461,8 +444,7 @@ finish_field:
                if (!p)
                        continue;
 
-               if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
-                       adios(EX_OSERR, NULL, "out of memory");
+               part = (struct part *) mh_xcalloc(1, sizeof(*part));
                *pp = part;
                pp = &part->mp_next;
                part->mp_part = p;
@@ -542,8 +524,7 @@ init_decoded_content(CT ct)
 {
        CE ce;
 
-       if ((ce = (CE) mh_xcalloc(1, sizeof(*ce))) == NULL)
-               adios(EX_OSERR, NULL, "out of memory");
+       ce = (CE) mh_xcalloc(1, sizeof(*ce));
 
        ct->c_cefile     = ce;
        ct->c_ceopenfnx  = open7Bit;  /* since unencoded */
@@ -603,8 +584,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp)
        }
 
        /* allocate basic Content structure */
-       if ((ct = (CT) mh_xcalloc(1, sizeof(*ct))) == NULL)
-               adios(EX_OSERR, NULL, "out of memory");
+       ct = (CT) mh_xcalloc(1, sizeof(*ct));
        *ctp = ct;
 
        /* allocate basic structure for handling decoded content */
@@ -912,9 +892,7 @@ use_forw:
                        ct->c_type = CT_MULTIPART;
                        ct->c_subtype = MULTI_DIGEST;
 
-                       if ((m = (struct multipart *)
-                                       mh_xcalloc(1, sizeof(*m))) == NULL)
-                               adios(EX_OSERR, NULL, "out of memory");
+                       m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
                        ct->c_ctparams = (void *) m;
                        pp = &m->mp_parts;
 
@@ -924,9 +902,7 @@ use_forw:
                                        CT p;
                                        CE pe;
 
-                                       if ((p = (CT) mh_xcalloc(1, sizeof(*p)))
-                                                       == NULL)
-                                               adios(EX_OSERR, NULL, "out of memory");
+                                       p = (CT) mh_xcalloc(1, sizeof(*p));
                                        init_decoded_content(p);
                                        pe = p->c_cefile;
                                        if (get_ctinfo("message/rfc822", p, 0)
@@ -940,8 +916,7 @@ use_forw:
                                                        msgnum);
                                        pe->ce_file = getcpy(buffer);
 
-                                       if ((part = (struct part *) mh_xcalloc(1, sizeof(*part))) == NULL)
-                                               adios(EX_OSERR, NULL, "out of memory");
+                                       part = (struct part *) mh_xcalloc(1, sizeof(*part));
                                        *pp = part;
                                        pp = &part->mp_next;
                                        part->mp_part = p;
@@ -1000,8 +975,7 @@ use_forw:
                ct->c_type = CT_MULTIPART;
                ct->c_subtype = vrsn;
 
-               if ((m = (struct multipart *) mh_xcalloc(1, sizeof(*m))) == NULL)
-                       adios(EX_OSERR, NULL, "out of memory");
+               m = (struct multipart *) mh_xcalloc(1, sizeof(*m));
                ct->c_ctparams = (void *) m;
 
                pp = &m->mp_parts;
@@ -1017,9 +991,7 @@ use_forw:
                        if (!p)
                                continue;
 
-                       if ((part = (struct part *)
-                                       mh_xcalloc(1, sizeof(*part))) == NULL)
-                               adios(EX_OSERR, NULL, "out of memory");
+                       part = (struct part *) mh_xcalloc(1, sizeof(*part));
                        *pp = part;
                        pp = &part->mp_next;
                        part->mp_part = p;