From 7a13a5266a14f1c6a13752db9292cd40c1211fba Mon Sep 17 00:00:00 2001 From: markus schnalke Date: Tue, 10 Nov 2015 06:53:44 +0100 Subject: [PATCH] No error-checking for error-checking alloc functions The mh_x(m|c|re)alloc function always return successful ... or terminate the program on their own, otherwise. --- uip/ap.c | 4 +--- uip/burst.c | 2 -- uip/mhbuild.c | 33 ++++++++++----------------------- uip/mhl.c | 7 ++----- uip/mhlist.c | 8 +++----- uip/mhparse.c | 22 +++++++--------------- uip/mhshow.c | 8 +++----- uip/mhstore.c | 11 ++++------- uip/mhtest.c | 8 +++----- uip/pick.c | 3 +-- uip/rcvdist.c | 12 ++++-------- uip/repl.c | 10 ++++------ uip/scansbr.c | 4 ---- uip/sortm.c | 2 -- 14 files changed, 42 insertions(+), 92 deletions(-) diff --git a/uip/ap.c b/uip/ap.c index 8156517..e2d43da 100644 --- a/uip/ap.c +++ b/uip/ap.c @@ -138,9 +138,7 @@ process(char *arg, int norm) (q = &pq)->pq_next = NULL; while ((cp = getname(arg))) { - if ((p = (struct pqpair *) - mh_xcalloc((size_t) 1, sizeof(*p))) == NULL) - adios(EX_OSERR, NULL, "unable to allocate pqpair memory"); + p = (struct pqpair *) mh_xcalloc((size_t) 1, sizeof(*p)); if ((mp = getm(cp, NULL, 0, norm, error)) == NULL) { p->pq_text = getcpy(cp); p->pq_error = getcpy(error); diff --git a/uip/burst.c b/uip/burst.c index 591d7f4..04e5450 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -119,8 +119,6 @@ main(int argc, char **argv) smsgs = (struct smsg *) mh_xcalloc((size_t) (MAXFOLDER + 2), sizeof(*smsgs)); - if (smsgs == NULL) - adios(EX_OSERR, NULL, "unable to allocate burst storage"); hi = mp->hghmsg + 1; diff --git a/uip/mhbuild.c b/uip/mhbuild.c index 01acdb7..76826c3 100644 --- a/uip/mhbuild.c +++ b/uip/mhbuild.c @@ -330,8 +330,7 @@ build_mime(char *infile) /* ** 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 @@ -435,8 +434,7 @@ build_mime(char *infile) 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; @@ -455,8 +453,7 @@ build_mime(char *infile) 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; @@ -536,8 +533,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 */ @@ -597,8 +593,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 */ @@ -906,9 +901,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; @@ -918,9 +911,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) @@ -934,8 +925,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; @@ -994,8 +984,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; @@ -1011,9 +1000,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; diff --git a/uip/mhl.c b/uip/mhl.c index f3f7477..6989c70 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -780,9 +780,7 @@ mcomp_format(struct mcomp *c1, struct mcomp *c2) (q = &pq)->pq_next = NULL; while ((cp = getname(ap))) { - if ((p = (struct pqpair *) - mh_xcalloc((size_t) 1, sizeof(*p))) == NULL) - adios(EX_OSERR, NULL, "unable to allocate pqpair memory"); + p = (struct pqpair *) mh_xcalloc((size_t) 1, sizeof(*p)); if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) { p->pq_text = getcpy(cp); @@ -829,8 +827,7 @@ add_queue(struct mcomp **head, struct mcomp **tail, char *name, { struct mcomp *c1; - if ((c1 = (struct mcomp *) mh_xcalloc((size_t) 1, sizeof(*c1))) == NULL) - adios(EX_OSERR, NULL, "unable to allocate comp memory"); + c1 = (struct mcomp *) mh_xcalloc((size_t) 1, sizeof(*c1)); c1->c_flags = flags & ~INIT; if ((c1->c_name = name ? getcpy(name) : NULL)) diff --git a/uip/mhlist.c b/uip/mhlist.c index 9022ecf..6d7b8e7 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -197,8 +197,7 @@ main(int argc, char **argv) ** check if message is coming from file */ if (file) { - if (!(cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)); ctp = cts; if ((ct = parse_mime(file))) @@ -232,9 +231,8 @@ main(int argc, char **argv) } seq_setprev(mp); /* set the previous-sequence */ - if (!(cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), - sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), + sizeof(*cts)); ctp = cts; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { diff --git a/uip/mhparse.c b/uip/mhparse.c index 4885572..b7b8694 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -238,8 +238,7 @@ get_content(FILE *in, char *file, int toplevel) HF hp; /* allocate the content structure */ - if (!(ct = (CT) mh_xcalloc(1, sizeof(*ct)))) - adios(EX_OSERR, NULL, "out of memory"); + ct = (CT) mh_xcalloc(1, sizeof(*ct)); ct->c_fp = in; ct->c_file = getcpy(file); @@ -977,8 +976,7 @@ InitText(CT ct) ct->c_subtype = kv->kv_value; /* allocate text character set structure */ - if ((t = (struct text *) mh_xcalloc(1, sizeof(*t))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + t = (struct text *) mh_xcalloc(1, sizeof(*t)); ct->c_ctparams = (void *) t; /* scan for charset parameter */ @@ -1059,8 +1057,7 @@ InitMultiPart(CT ct) } /* allocate primary structure for multipart info */ - 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; /* check if boundary parameter contains only whitespace characters */ @@ -1103,9 +1100,7 @@ InitMultiPart(CT ct) if (strcmp(buffer + 2, m->mp_start)!=0) continue; next_part: - 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)); *next = part; next = &part->mp_next; @@ -1219,8 +1214,7 @@ reverse_parts(CT ct) i++; /* allocate array of pointers to the parts */ - if (!(base = (struct part **) mh_xcalloc((size_t) (i + 1), sizeof(*base)))) - adios(EX_OSERR, NULL, "out of memory"); + base = (struct part **) mh_xcalloc((size_t) (i + 1), sizeof(*base)); bmp = base; /* point at all the parts */ @@ -1276,8 +1270,7 @@ InitMessage(CT ct) char **ap, **ep; struct partial *p; - if ((p = (struct partial *) mh_xcalloc(1, sizeof(*p))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + p = (struct partial *) mh_xcalloc(1, sizeof(*p)); ct->c_ctparams = (void *) p; /* @@ -1389,8 +1382,7 @@ init_encoding(CT ct, OpenCEFunc openfnx) { 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 = openfnx; diff --git a/uip/mhshow.c b/uip/mhshow.c index f48fa99..bb03939 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -249,8 +249,7 @@ main(int argc, char **argv) ** check if message is coming from file */ if (file) { - if (!(cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)); ctp = cts; if ((ct = parse_mime(file))) @@ -304,9 +303,8 @@ main(int argc, char **argv) seq_setprev(mp); /* set the Previous-Sequence */ seq_setunseen(mp, 0); /* unset unseen seqs for shown msgs */ - if (!(cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), - sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), + sizeof(*cts)); ctp = cts; /* diff --git a/uip/mhstore.c b/uip/mhstore.c index 1202fcb..fae054f 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -261,8 +261,7 @@ main(int argc, char **argv) ** check if message is coming from file */ if (file) { - if (!(cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)); ctp = cts; if ((ct = parse_mime(file))) @@ -294,9 +293,8 @@ main(int argc, char **argv) exit(EX_USAGE); seq_setprev(mp); /* set the previous-sequence */ - if (!(cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), - sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), + sizeof(*cts)); ctp = cts; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { @@ -570,8 +568,7 @@ store_partial(CT ct) return NOTOK; } - if ((base = (CT *) mh_xcalloc((size_t) (i + 1), sizeof(*base))) == NULL) - adios(EX_OSERR, NULL, "out of memory"); + base = (CT *) mh_xcalloc((size_t) (i + 1), sizeof(*base)); ctq = base; for (ctp = cts; *ctp; ctp++) { diff --git a/uip/mhtest.c b/uip/mhtest.c index 43fde0e..dd45626 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -209,8 +209,7 @@ main(int argc, char **argv) ** check if message is coming from file */ if (file) { - if (!(cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) 2, sizeof(*cts)); ctp = cts; if ((ct = parse_mime(file))) @@ -242,9 +241,8 @@ main(int argc, char **argv) exit(EX_USAGE); seq_setprev(mp); /* set the previous-sequence */ - if (!(cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), - sizeof(*cts)))) - adios(EX_OSERR, NULL, "out of memory"); + cts = (CT *) mh_xcalloc((size_t) (mp->numsel + 1), + sizeof(*cts)); ctp = cts; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { diff --git a/uip/pick.c b/uip/pick.c index 2d2bd65..320db19 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -768,8 +768,7 @@ newnexus(int (*action)()) { struct nexus *p; - if ((p = (struct nexus *) mh_xcalloc((size_t) 1, sizeof *p)) == NULL) - adios(EX_OSERR, NULL, "unable to allocate component storage"); + p = (struct nexus *) mh_xcalloc((size_t) 1, sizeof *p); p->n_action = action; return p; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 1337c89..53cc0f0 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -170,15 +170,11 @@ rcvdistout(FILE *inb, char *form, char *addrs) cp = new_fs(form ? form : rcvdistcomps, NULL); format_len = strlen(cp); ncomps = fmt_compile(cp, &fmt) + 1; - if (!(nxtbuf = compbuffers = - (char **) mh_xcalloc((size_t) ncomps, sizeof(char *)))) { - adios(EX_OSERR, NULL, "unable to allocate component buffers"); - } - if (!(savecomp = used_buf = + nxtbuf = compbuffers = + (char **) mh_xcalloc((size_t) ncomps, sizeof(char *)); + savecomp = used_buf = (struct comp **) mh_xcalloc((size_t) (ncomps + 1), - sizeof(struct comp *)))) { - adios(EX_OSERR, NULL, "unable to allocate component buffer stack"); - } + sizeof(struct comp *)); savecomp += ncomps + 1; *--savecomp = 0; diff --git a/uip/repl.c b/uip/repl.c index c0b290d..f5df9ec 100644 --- a/uip/repl.c +++ b/uip/repl.c @@ -412,12 +412,10 @@ replout(FILE *inb, char *drft, struct msgs *mp, /* compile format string */ ncomps = fmt_compile(cp, &fmt) + 1; - if (!(nxtbuf = compbuffers = (char **) - mh_xcalloc((size_t) ncomps, sizeof(char *)))) - adios(EX_OSERR, NULL, "unable to allocate component buffers"); - if (!(savecomp = used_buf = (struct comp **) - mh_xcalloc((size_t) (ncomps+1), sizeof(struct comp *)))) - adios(EX_OSERR, NULL, "unable to allocate component buffer stack"); + nxtbuf = compbuffers = (char **) + mh_xcalloc((size_t) ncomps, sizeof(char *)); + savecomp = used_buf = (struct comp **) + mh_xcalloc((size_t) (ncomps+1), sizeof(struct comp *)); savecomp += ncomps + 1; *--savecomp = NULL; /* point at zero'd end minus 1 */ diff --git a/uip/scansbr.c b/uip/scansbr.c index ade3a28..d985a5c 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -100,12 +100,8 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg, nxtbuf = compbuffers = (char **) mh_xcalloc((size_t) ncomps, sizeof(char *)); - if (!nxtbuf) - adios(EX_OSERR, NULL, "unable to allocate component buffers"); used_buf = (struct comp **) mh_xcalloc((size_t) (ncomps+1), sizeof(struct comp *)); - if (!used_buf) - adios(EX_OSERR, NULL, "unable to allocate component buffer stack"); /* NULL-terminate array */ used_buf += ncomps; *used_buf = NULL; diff --git a/uip/sortm.c b/uip/sortm.c index 4ca0c72..5d15ed6 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -297,8 +297,6 @@ read_hdrs(struct msgs *mp, char *datesw) smsgs = (struct smsg *) mh_xcalloc((size_t) (mp->hghsel - mp->lowsel + 2), sizeof(*smsgs)); - if (smsgs == NULL) - adios(EX_OSERR, NULL, "unable to allocate sort storage"); s = smsgs; for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { -- 1.7.10.4