From 81a21a9a97d8633f6d6231e31fdb6e328d0d3ff2 Mon Sep 17 00:00:00 2001 From: Josh Bressers Date: Mon, 2 Jan 2006 03:17:41 +0000 Subject: [PATCH] * patch #3966: Create a mh_xmalloc function to prevent mistakes when calling malloc. --- ChangeLog | 5 +++++ h/utils.h | 9 +++++++++ sbr/Makefile.in | 2 +- sbr/add.c | 4 ++-- sbr/brkstring.c | 4 ++-- sbr/client.c | 6 +++--- sbr/concat.c | 4 ++-- sbr/context_foil.c | 6 ++---- sbr/context_replace.c | 8 +++----- sbr/fmt_addr.c | 5 ++--- sbr/fmt_new.c | 4 ++-- sbr/fmt_rfc2047.c | 4 ++-- sbr/folder_read.c | 10 ++++------ sbr/folder_realloc.c | 6 ++---- sbr/getarguments.c | 4 ++-- sbr/getcpy.c | 7 +++---- sbr/lock_file.c | 9 +++------ sbr/m_getfld.c | 3 ++- sbr/mf.c | 12 ++++++------ sbr/mts.c | 5 +++-- sbr/putenv.c | 7 +++---- sbr/readconfig.c | 4 ++-- sbr/ruserpass.c | 9 +++++---- sbr/seq_list.c | 4 ++-- sbr/strdup.c | 4 ++-- sbr/utils.c | 29 +++++++++++++++++++++++++++++ sbr/vfgets.c | 4 ++-- uip/aliasbr.c | 11 ++++------- uip/anno.c | 4 ++-- uip/annosbr.c | 7 +++---- uip/conflict.c | 4 ++-- uip/flist.c | 8 ++++---- uip/folder.c | 7 +++---- uip/forw.c | 4 ++-- uip/install-mh.c | 4 ++-- uip/mark.c | 4 ++-- uip/mhbuildsbr.c | 7 +++---- uip/mhlist.c | 4 ++-- uip/mhlsbr.c | 7 +++---- uip/mhn.c | 3 +-- uip/mhparse.c | 7 +++---- uip/mhpath.c | 4 ++-- uip/mhshow.c | 4 ++-- uip/mhstore.c | 4 ++-- uip/mhtest.c | 4 ++-- uip/mshcmds.c | 4 ++-- uip/packf.c | 4 ++-- uip/pick.c | 4 ++-- uip/popi.c | 4 ++-- uip/popsbr.c | 10 ++++------ uip/rcvdist.c | 6 +++--- uip/refile.c | 4 ++-- uip/replsbr.c | 10 ++++------ uip/rmm.c | 4 ++-- uip/scan.c | 4 ++-- uip/scansbr.c | 7 +++---- uip/sendsbr.c | 4 ++-- uip/sortm.c | 16 +++++----------- uip/vmhsbr.c | 4 ++-- uip/whatnowsbr.c | 4 ++-- 60 files changed, 188 insertions(+), 176 deletions(-) create mode 100644 h/utils.h create mode 100644 sbr/utils.c diff --git a/ChangeLog b/ChangeLog index 4bfa786..f8d1c8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2006-01-01 Josh Bressers + + * patch #3966: Create a mh_xmalloc function to prevent mistakes when + calling malloc. + 2005-12-24 Peter Maydell * Bug #15285: Don't use $< in target rules in makefiles, as POSIX diff --git a/h/utils.h b/h/utils.h new file mode 100644 index 0000000..aba8fc4 --- /dev/null +++ b/h/utils.h @@ -0,0 +1,9 @@ + +/* + * utils.h -- utility prototypes + * + * $Id$ + */ + +void *mh_xmalloc(size_t); + diff --git a/sbr/Makefile.in b/sbr/Makefile.in index 08845c3..17d82e8 100644 --- a/sbr/Makefile.in +++ b/sbr/Makefile.in @@ -75,7 +75,7 @@ SRCS = add.c addrsbr.c ambigsw.c atooi.c brkstring.c \ seq_setprev.c seq_setunseen.c showfile.c signals.c \ smatch.c snprintb.c ssequal.c strcasecmp.c \ strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c \ - m_msgdef.c mf.c + m_msgdef.c mf.c utils.c # source for compatibility functions COMPAT = snprintf.c strdup.c strerror.c diff --git a/sbr/add.c b/sbr/add.c index f977c27..40201c1 100644 --- a/sbr/add.c +++ b/sbr/add.c @@ -15,6 +15,7 @@ */ #include +#include char * add (char *s2, char *s1) @@ -28,8 +29,7 @@ add (char *s2, char *s1) len2 = strlen (s2); - if (!(cp = malloc (len1 + len2 + 1))) - adios (NULL, "unable to allocate string storage"); + cp = mh_xmalloc (len1 + len2 + 1); /* Copy s1 and free it */ if (s1) { diff --git a/sbr/brkstring.c b/sbr/brkstring.c index 27f187e..255abf7 100644 --- a/sbr/brkstring.c +++ b/sbr/brkstring.c @@ -11,6 +11,7 @@ */ #include +#include /* allocate this number of pointers at a time */ #define NUMBROKEN 256 @@ -33,8 +34,7 @@ brkstring (char *str, char *brksep, char *brkterm) /* allocate initial space for pointers on first call */ if (!broken) { len = NUMBROKEN; - if (!(broken = (char **) malloc ((size_t) (len * sizeof(*broken))))) - adios (NULL, "unable to malloc array in brkstring"); + broken = (char **) mh_xmalloc ((size_t) (len * sizeof(*broken))); } /* diff --git a/sbr/client.c b/sbr/client.c index a7ab764..0d0454c 100644 --- a/sbr/client.c +++ b/sbr/client.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -270,7 +271,7 @@ rcaux (struct servent *sp, struct hostent *hp, int rproto, strncpy (response, "Out of memory.", len_response); return OOPS2; } - ticket = (KTEXT) malloc (sizeof(KTEXT_ST)); + ticket = (KTEXT) mh_xmalloc (sizeof(KTEXT_ST)); rem = krb_sendauth (0L, sd, ticket, kservice, instance, (char *) krb_realmofhost (instance), (unsigned long) 0, &msg_data, &cred, schedule, @@ -474,8 +475,7 @@ client_getcpy (char *str) size_t len; len = strlen(str) + 1; - if (!(cp = malloc(len))) - return NULL; + cp = mh_xmalloc(len); memcpy (cp, str, len); return cp; diff --git a/sbr/concat.c b/sbr/concat.c index a338835..4d4e15c 100644 --- a/sbr/concat.c +++ b/sbr/concat.c @@ -11,6 +11,7 @@ */ #include +#include char * @@ -26,8 +27,7 @@ concat (char *s1, ...) len += strlen (cp); va_end(list); - if (!(dp = sp = malloc(len))) - adios (NULL, "unable to allocate string storage"); + dp = sp = mh_xmalloc(len); sp = copy(s1, sp); diff --git a/sbr/context_foil.c b/sbr/context_foil.c index d6c90c4..7eccd79 100644 --- a/sbr/context_foil.c +++ b/sbr/context_foil.c @@ -10,6 +10,7 @@ */ #include +#include /* * Foil search of users .mh_profile @@ -45,10 +46,7 @@ context_foil (char *path) * If path is given, create a minimal profile/context list */ if (path) { - if (!(m_defs = (struct node *) malloc (sizeof(*np)))) { - advise (NULL, "unable to allocate profile storage"); - return -1; - } + m_defs = (struct node *) mh_xmalloc (sizeof(*np)); np = m_defs; if (!(np->n_name = strdup ("Path"))) { diff --git a/sbr/context_replace.c b/sbr/context_replace.c index b723cb4..2cdadf0 100644 --- a/sbr/context_replace.c +++ b/sbr/context_replace.c @@ -10,6 +10,7 @@ */ #include +#include void @@ -21,8 +22,7 @@ context_replace (char *key, char *value) * If list is emtpy, allocate head of profile/context list. */ if (!m_defs) { - if (!(m_defs = (struct node *) malloc (sizeof(*np)))) - adios (NULL, "unable to allocate profile storage"); + m_defs = (struct node *) mh_xmalloc (sizeof(*np)); np = m_defs; np->n_name = getcpy (key); @@ -56,9 +56,7 @@ context_replace (char *key, char *value) /* * Else add this new entry at the end */ - np->n_next = (struct node *) malloc (sizeof(*np)); - if (!np->n_next) - adios (NULL, "unable to allocate profile storage"); + np->n_next = (struct node *) mh_xmalloc (sizeof(*np)); np = np->n_next; np->n_name = getcpy (key); diff --git a/sbr/fmt_addr.c b/sbr/fmt_addr.c index 2e4bff6..97f4271 100644 --- a/sbr/fmt_addr.c +++ b/sbr/fmt_addr.c @@ -12,6 +12,7 @@ #include #include #include +#include static char *buf; /* our current working buffer */ static char *bufend; /* end of working buffer */ @@ -63,9 +64,7 @@ formataddr (char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = malloc (BUFINCR); - if (! buf) - adios (NULL, "formataddr: couldn't allocate buffer space"); + buf = mh_xmalloc (BUFINCR); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index effd06f..c1bc7c7 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -10,6 +10,7 @@ */ #include +#include #define QUOTE '\\' @@ -41,8 +42,7 @@ new_fs (char *form, char *format, char *default_fs) if (fstat (fileno (fp), &st) == -1) adios (form, "unable to stat format file"); - if (!(formats = malloc ((size_t) st.st_size + 1))) - adios (form, "unable to allocate space for format"); + formats = mh_xmalloc ((size_t) st.st_size + 1); if (read (fileno(fp), formats, (int) st.st_size) != st.st_size) adios (form, "error reading format file"); diff --git a/sbr/fmt_rfc2047.c b/sbr/fmt_rfc2047.c index 9f5b26d..0eb71bd 100644 --- a/sbr/fmt_rfc2047.c +++ b/sbr/fmt_rfc2047.c @@ -10,6 +10,7 @@ */ #include +#include #ifdef HAVE_ICONV # include # include @@ -198,8 +199,7 @@ decode_rfc2047 (char *str, char *dst, size_t dstlen) if (use_iconv) { saveq = q; savedstlen = dstlen; - if (!(q = convbuf = (char *)malloc(endofmime - startofmime))) - continue; + q = convbuf = (char *) mh_xmalloc(endofmime - startofmime); } /* ADDCHR2 is for adding characters when q is or might be convbuf: * in this case on buffer-full we want to run iconv before returning. diff --git a/sbr/folder_read.c b/sbr/folder_read.c index 6cd0d10..8e3a3ff 100644 --- a/sbr/folder_read.c +++ b/sbr/folder_read.c @@ -10,6 +10,7 @@ */ #include +#include /* We allocate the `mi' array 1024 elements at a time */ #define NUMMSGS 1024 @@ -44,8 +45,7 @@ folder_read (char *name) } /* Allocate the main structure for folder information */ - if (!(mp = (struct msgs *) malloc ((size_t) sizeof(*mp)))) - adios (NULL, "unable to allocate folder storage"); + mp = (struct msgs *) mh_xmalloc ((size_t) sizeof(*mp)); clear_folder_flags (mp); mp->foldpath = name; @@ -66,8 +66,7 @@ folder_read (char *name) * name of the messages in this folder. */ len = NUMMSGS; - if (!(mi = (int *) malloc ((size_t) (len * sizeof(*mi))))) - adios (NULL, "unable to allocate storage"); + mi = (int *) mh_xmalloc ((size_t) (len * sizeof(*mi))); while ((dp = readdir (dd))) { if ((msgnum = m_atoi (dp->d_name)) && msgnum > 0) { @@ -138,8 +137,7 @@ folder_read (char *name) /* * Allocate space for status of each message. */ - if (!(mp->msgstats = malloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)))) - adios (NULL, "unable to allocate storage for msgstats"); + mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)); /* * Clear all the flag bits for all the message diff --git a/sbr/folder_realloc.c b/sbr/folder_realloc.c index f3d99ba..753da2e 100644 --- a/sbr/folder_realloc.c +++ b/sbr/folder_realloc.c @@ -10,6 +10,7 @@ */ #include +#include /* * Reallocate some of the space in the folder @@ -58,10 +59,7 @@ folder_realloc (struct msgs *mp, int lo, int hi) seqset_t *tmpstats; /* first allocate the new message status space */ - if (!(tmpstats = malloc (MSGSTATSIZE(mp, lo, hi)))) { - advise (NULL, "unable to reallocate message storage"); - return NULL; - } + tmpstats = mh_xmalloc (MSGSTATSIZE(mp, lo, hi)); /* then copy messages status array with shift */ if (mp->nummsg > 0) { diff --git a/sbr/getarguments.c b/sbr/getarguments.c index 89b57c1..fc3d2c0 100644 --- a/sbr/getarguments.c +++ b/sbr/getarguments.c @@ -10,6 +10,7 @@ */ #include +#include char ** getarguments (char *invo_name, int argc, char **argv, int check_context) @@ -30,8 +31,7 @@ getarguments (char *invo_name, int argc, char **argv, int check_context) n++; } - if (!(arguments = (char **) malloc ((argc + n) * sizeof(*arguments)))) - adios (NULL, "unable to malloc argument storage"); + arguments = (char **) mh_xmalloc ((argc + n) * sizeof(*arguments)); bp = arguments; /* Copy any arguments from profile/context */ diff --git a/sbr/getcpy.c b/sbr/getcpy.c index f23641d..1186831 100644 --- a/sbr/getcpy.c +++ b/sbr/getcpy.c @@ -14,6 +14,7 @@ */ #include +#include char * @@ -24,12 +25,10 @@ getcpy (char *str) if (str) { len = strlen(str) + 1; - if (!(cp = malloc (len))) - adios (NULL, "unable to allocate string storage"); + cp = mh_xmalloc (len); memcpy (cp, str, len); } else { - if (!(cp = malloc ((size_t) 1))) - adios (NULL, "unable to allocate string storage"); + cp = mh_xmalloc ((size_t) 1); *cp = '\0'; } return cp; diff --git a/sbr/lock_file.c b/sbr/lock_file.c index cda66ab..a98d5b1 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -19,6 +19,7 @@ #include #include +#include #ifdef TIME_WITH_SYS_TIME # include @@ -542,15 +543,11 @@ timerON (char *curlock, int fd) struct lock *lp; size_t len; - if (!(lp = (struct lock *) malloc (sizeof(*lp)))) - return; + lp = (struct lock *) mh_xmalloc (sizeof(*lp)); len = strlen(curlock) + 1; lp->l_fd = fd; - if (!(lp->l_lock = malloc (len))) { - free ((char *) lp); - return; - } + lp->l_lock = mh_xmalloc (len); memcpy (lp->l_lock, curlock, len); lp->l_next = l_top; diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index 1332405..c085bf5 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -11,6 +11,7 @@ #include #include +#include /* This module has a long and checkered history. First, it didn't burst maildrops correctly because it considered two CTRL-A:s in a row to be @@ -562,7 +563,7 @@ m_unknown(FILE *iob) msg_style = MS_MMDF; } c = strlen (delimstr); - fdelim = (unsigned char *) malloc((size_t) (c + 3)); + fdelim = (unsigned char *) mh_xmalloc((size_t) (c + 3)); *fdelim++ = '\0'; *fdelim = '\n'; msg_delim = (char *)fdelim+1; diff --git a/sbr/mf.c b/sbr/mf.c index 27c06bb..9a2c647 100644 --- a/sbr/mf.c +++ b/sbr/mf.c @@ -12,6 +12,7 @@ #include #include #include +#include /* * static prototypes @@ -42,8 +43,8 @@ getcpy (char *s) for(;;) pause(); } - if ((p = malloc ((size_t) (strlen (s) + 2)))) - strcpy (p, s); + p = mh_xmalloc ((size_t) (strlen (s) + 2)); + strcpy (p, s); return p; } @@ -56,8 +57,8 @@ add (char *s1, char *s2) if (!s2) return getcpy (s1); - if ((p = malloc ((size_t) (strlen (s1) + strlen (s2) + 2)))) - sprintf (p, "%s%s", s2, s1); + p = mh_xmalloc ((size_t) (strlen (s1) + strlen (s2) + 2)); + sprintf (p, "%s%s", s2, s1); free (s2); return p; } @@ -934,8 +935,7 @@ mfgets (FILE *in, char **bp) static char *pp = NULL; if (pp == NULL) - if (!(pp = malloc ((size_t) (len = BUFSIZ)))) - return NOTOK; + pp = mh_xmalloc ((size_t) (len = BUFSIZ)); for (ep = (cp = pp) + len - 2;;) { switch (i = getc (in)) { diff --git a/sbr/mts.c b/sbr/mts.c index 169894f..7941e09 100644 --- a/sbr/mts.c +++ b/sbr/mts.c @@ -11,6 +11,7 @@ #include /* for snprintf() */ #include +#include #define nmhetcdir(file) NMHETCDIR#file @@ -271,8 +272,8 @@ tailor_value (char *s) *bp = 0; len = strlen (buffer) + 1; - if ((bp = malloc (len))) - memcpy (bp, buffer, len); + bp = mh_xmalloc (len); + memcpy (bp, buffer, len); return bp; } diff --git a/sbr/putenv.c b/sbr/putenv.c index 649b015..fb4a77c 100644 --- a/sbr/putenv.c +++ b/sbr/putenv.c @@ -10,6 +10,7 @@ */ #include +#include extern char **environ; @@ -27,8 +28,7 @@ m_putenv (char *name, char *value) register int i; register char **ep, **nep, *cp; - if (!(cp = malloc ((size_t) (strlen (name) + strlen (value) + 2)))) - return 1; + cp = mh_xmalloc ((size_t) (strlen (name) + strlen (value) + 2)); sprintf (cp, "%s=%s", name, value); @@ -38,8 +38,7 @@ m_putenv (char *name, char *value) return 0; } - if (!(nep = (char **) malloc ((size_t) ((i + 2) * sizeof(*nep))))) - return 1; + nep = (char **) mh_xmalloc ((size_t) ((i + 2) * sizeof(*nep))); for (ep = environ, i = 0; *ep; nep[i++] = *ep++) continue; diff --git a/sbr/readconfig.c b/sbr/readconfig.c index 9e0382e..eba6eec 100644 --- a/sbr/readconfig.c +++ b/sbr/readconfig.c @@ -11,6 +11,7 @@ */ #include +#include struct procstr { char *procname; @@ -65,8 +66,7 @@ readconfig (struct node **npp, FILE *ib, char *file, int ctx) case FLD: case FLDPLUS: case FLDEOF: - if (!(np = (struct node *) malloc (sizeof(*np)))) - adios (NULL, "unable to allocate profile storage"); + np = (struct node *) mh_xmalloc (sizeof(*np)); *npp = np; *(npp = &np->n_next) = NULL; np->n_name = getcpy (name); diff --git a/sbr/ruserpass.c b/sbr/ruserpass.c index 4c12b71..3097ee7 100644 --- a/sbr/ruserpass.c +++ b/sbr/ruserpass.c @@ -19,6 +19,7 @@ */ #include +#include #include #include @@ -100,7 +101,7 @@ match: switch(t) { case LOGIN: if (token() && *aname == 0) { - *aname = malloc((size_t) strlen(tokval) + 1); + *aname = mh_xmalloc((size_t) strlen(tokval) + 1); strcpy(*aname, tokval); } break; @@ -112,7 +113,7 @@ match: goto bad; } if (token() && *apass == 0) { - *apass = malloc((size_t) strlen(tokval) + 1); + *apass = mh_xmalloc((size_t) strlen(tokval) + 1); strcpy(*apass, tokval); } break; @@ -153,7 +154,7 @@ done: myname = tmp; } - *aname = malloc((size_t) strlen(myname) + 1); + *aname = mh_xmalloc((size_t) strlen(myname) + 1); strcpy (*aname, myname); } @@ -168,7 +169,7 @@ done: mypass = *aname; } - *apass = malloc((size_t) strlen(mypass) + 1); + *apass = mh_xmalloc((size_t) strlen(mypass) + 1); strcpy (*apass, mypass); } diff --git a/sbr/seq_list.c b/sbr/seq_list.c index 8a44069..ecc03bf 100644 --- a/sbr/seq_list.c +++ b/sbr/seq_list.c @@ -11,6 +11,7 @@ */ #include +#include /* allocate this much buffer space at a time */ #define MAXBUFFER 1024 @@ -29,8 +30,7 @@ seq_list(struct msgs *mp, char *seqname) /* On first invocation, allocate initial buffer space */ if (!buffer) { len = MAXBUFFER; - if (!(buffer = malloc ((size_t) len))) - adios (NULL, "unable to malloc storage in seq_list"); + buffer = mh_xmalloc ((size_t) len); } /* diff --git a/sbr/strdup.c b/sbr/strdup.c index 486b36a..ebc29f5 100644 --- a/sbr/strdup.c +++ b/sbr/strdup.c @@ -10,6 +10,7 @@ */ #include +#include char * @@ -22,8 +23,7 @@ strdup (const char *str) return NULL; len = strlen(str) + 1; - if (!(cp = malloc (len))) - return NULL; + cp = mh_xmalloc (len); memcpy (cp, str, len); return cp; } diff --git a/sbr/utils.c b/sbr/utils.c new file mode 100644 index 0000000..bc17177 --- /dev/null +++ b/sbr/utils.c @@ -0,0 +1,29 @@ + +/* + * utils.c -- various utility routines + * + * $Id$ + * + * This code is Copyright (c) 2006, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include +#include +#include + +void * +mh_xmalloc(size_t size) +{ + void *memory; + + if (size == 0) + adios(NULL, "Tried to malloc 0 bytes"); + + memory = malloc(size); + if (!memory) + adios(NULL, "Malloc failed"); + + return memory; +} diff --git a/sbr/vfgets.c b/sbr/vfgets.c index 39cfaa2..beb0afd 100644 --- a/sbr/vfgets.c +++ b/sbr/vfgets.c @@ -10,6 +10,7 @@ */ #include +#include #define QUOTE '\\' @@ -23,8 +24,7 @@ vfgets (FILE *in, char **bp) static char *pp = NULL; if (pp == NULL) - if (!(pp = malloc ((size_t) (len = BUFSIZ)))) - adios (NULL, "unable to allocate string storage"); + pp = mh_xmalloc ((size_t) (len = BUFSIZ)); for (ep = (cp = pp) + len - 1;;) { if (fgets (cp, ep - cp + 1, in) == NULL) { diff --git a/uip/aliasbr.c b/uip/aliasbr.c index 19f204f..d0c193d 100644 --- a/uip/aliasbr.c +++ b/uip/aliasbr.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -475,9 +476,7 @@ add_aka (struct aka *ak, char *pp) if (!strcmp (pp, ad->ad_text)) return; - ad = (struct adr *) malloc (sizeof(*ad)); - if (ad == NULL) - return; + ad = (struct adr *) mh_xmalloc (sizeof(*ad)); ad->ad_text = getcpy (pp); ad->ad_local = strchr(pp, '@') == NULL && strchr(pp, '!') == NULL; ad->ad_next = NULL; @@ -522,8 +521,7 @@ akalloc (char *id) { register struct aka *p; - if (!(p = (struct aka *) malloc (sizeof(*p)))) - return NULL; + p = (struct aka *) mh_xmalloc (sizeof(*p)); p->ak_name = getcpy (id); p->ak_visible = 0; @@ -544,8 +542,7 @@ hmalloc (struct passwd *pw) { register struct home *p; - if (!(p = (struct home *) malloc (sizeof(*p)))) - return NULL; + p = (struct home *) mh_xmalloc (sizeof(*p)); p->h_name = getcpy (pw->pw_name); p->h_uid = pw->pw_uid; diff --git a/uip/anno.c b/uip/anno.c index dca93eb..d90e0f6 100644 --- a/uip/anno.c +++ b/uip/anno.c @@ -46,6 +46,7 @@ */ #include +#include /* * We allocate space for messages (msgs array) @@ -127,8 +128,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); while ((cp = *argp++)) { if (*cp == '-') { diff --git a/uip/annosbr.c b/uip/annosbr.c index 6677d21..337a01b 100644 --- a/uip/annosbr.c +++ b/uip/annosbr.c @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -93,8 +94,7 @@ annolist(char *file, char *comp, char *text, int number) * This buffer might need to be quite large, so we grow it as needed. */ - if ((field = (char *)malloc(field_size = 256)) == (char *)0) - adios(NULL, "can't allocate field buffer."); + field = (char *)mh_xmalloc(field_size = 256); /* * Get the length of the field name since we use it often. @@ -208,8 +208,7 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in if ((fp = fdopen(fd, "r")) == (FILE *)0) adios(NULL, "unable to fdopen file."); - if ((field = (char *)malloc(field_size = 256)) == (char *)0) - adios(NULL, "can't allocate field buffer."); + field = (char *)mh_xmalloc(field_size = 256); } /* diff --git a/uip/conflict.c b/uip/conflict.c index 32b1613..5097119 100644 --- a/uip/conflict.c +++ b/uip/conflict.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -189,8 +190,7 @@ grp_names (void) /* allocate space NGRPS at a time */ numgroups = 0; maxgroups = NGRPS; - if (!(grps = (char **) malloc((size_t) (maxgroups * sizeof(*grps))))) - adios (NULL, "unable to allocate group name storage"); + grps = (char **) mh_xmalloc((size_t) (maxgroups * sizeof(*grps))); setgrent (); while ((gr = getgrent ())) { diff --git a/uip/flist.c b/uip/flist.c index 408f608..1e850cb 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -17,6 +17,7 @@ */ #include +#include #define FALSE 0 #define TRUE 1 @@ -148,8 +149,7 @@ main(int argc, char **argv) /* allocate the initial space to record the folder names */ numfolders = 0; maxfolders = MAXFOLDERS; - if (!(foldersToDo = (char **) malloc ((size_t) (maxfolders * sizeof(*foldersToDo))))) - adios (NULL, "unable to allocate folder storage"); + foldersToDo = (char **) mh_xmalloc ((size_t) (maxfolders * sizeof(*foldersToDo))); /* no sequences yet */ numsequences = 0; @@ -306,7 +306,7 @@ GetFolderOrder(void) AllocFolders(&orders, &nOrdersAlloced, nOrders + 1); o = &orders[nOrders++]; o->priority = priority++; - o->name = (char *) malloc(p - s + 1); + o->name = (char *) mh_xmalloc(p - s + 1); strncpy(o->name, s, p - s); o->name[p - s] = 0; } else @@ -652,7 +652,7 @@ AllocFolders(struct Folder **f, int *nfa, int n) return; if (*f == NULL) { *nfa = 10; - *f = (struct Folder *) malloc (*nfa * (sizeof(struct Folder))); + *f = (struct Folder *) mh_xmalloc (*nfa * (sizeof(struct Folder))); } else { *nfa *= 2; *f = (struct Folder *) realloc (*f, *nfa * (sizeof(struct Folder))); diff --git a/uip/folder.c b/uip/folder.c index e4779dc..3348ae5 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -12,6 +12,7 @@ */ #include +#include #include static struct swit switches[] = { @@ -353,13 +354,11 @@ main (int argc, char **argv) /* Allocate initial space to record folder names */ maxfolders = NUMFOLDERS; - if ((folds = malloc (maxfolders * sizeof(char *))) == NULL) - adios (NULL, "unable to allocate storage for folder names"); + folds = mh_xmalloc (maxfolders * sizeof(char *)); /* Allocate initial space to record folder information */ maxFolderInfo = NUMFOLDERS; - if ((fi = malloc (maxFolderInfo * sizeof(*fi))) == NULL) - adios (NULL, "unable to allocate storage for folder info"); + fi = mh_xmalloc (maxFolderInfo * sizeof(*fi)); /* * Scan the folders diff --git a/uip/forw.c b/uip/forw.c index e842d26..319cc39 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -13,6 +13,7 @@ #include #include #include +#include #define IFORMAT "digest-issue-%s" @@ -688,8 +689,7 @@ build_form (char *form, char *digest, int volume, int issue) if ((in = dup (fileno (tmp))) == NOTOK) adios ("dup", "unable to"); - if ((line = malloc ((unsigned) fmtsize)) == NULL) - adios (NULL, "unable to allocate format line storage"); + line = mh_xmalloc ((unsigned) fmtsize); fmt_scan (fmt, line, fmtsize, dat); fputs (line, tmp); free (line); diff --git a/uip/install-mh.c b/uip/install-mh.c index 34aed95..ec847fb 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -9,6 +9,7 @@ */ #include /* mh internals */ +#include #include /* structure for getpwuid() results */ static struct swit switches[] = { @@ -180,8 +181,7 @@ query: /* * Add some initial elements to the profile/context list */ - if (!(m_defs = (struct node *) malloc (sizeof *np))) - adios (NULL, "unable to allocate profile storage"); + m_defs = (struct node *) mh_xmalloc (sizeof *np); np = m_defs; np->n_name = getcpy ("Path"); np->n_field = getcpy (pathname); diff --git a/uip/mark.c b/uip/mark.c index aeed866..27652e0 100644 --- a/uip/mark.c +++ b/uip/mark.c @@ -12,6 +12,7 @@ */ #include +#include /* * We allocate space for messages (msgs array) @@ -81,8 +82,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhbuildsbr.c b/uip/mhbuildsbr.c index fb2d451..64ec8a6 100644 --- a/uip/mhbuildsbr.c +++ b/uip/mhbuildsbr.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef TIME_WITH_SYS_TIME # include @@ -785,8 +786,7 @@ add_header (CT ct, char *name, char *value) HF hp; /* allocate header field structure */ - if (!(hp = malloc (sizeof(*hp)))) - adios (NULL, "out of memory"); + hp = mh_xmalloc (sizeof(*hp)); /* link data into header structure */ hp->name = name; @@ -1553,8 +1553,7 @@ invalid_param: goto no_body; } - if ((e->eb_body = bp = malloc ((unsigned) size)) == NULL) - adios (NULL, "out of memory"); + e->eb_body = bp = mh_xmalloc ((unsigned) size); fseek (p->c_fp, p->c_begin, SEEK_SET); while (size > 0) switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) { diff --git a/uip/mhlist.c b/uip/mhlist.c index 4fc17dc..56d9398 100644 --- a/uip/mhlist.c +++ b/uip/mhlist.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include @@ -153,8 +154,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index c310e2a..af3fa55 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -955,8 +956,7 @@ mhlfile (FILE *fp, char *mname, int ofilen, int ofilec) continue; } if (dobody && !strcasecmp (c1->c_name, "body")) { - if ((holder.c_text = malloc (sizeof(buf))) == NULL) - adios (NULL, "unable to allocate buffer memory"); + holder.c_text = mh_xmalloc (sizeof(buf)); strncpy (holder.c_text, buf, sizeof(buf)); while (state == BODY) { putcomp (c1, &holder, BODYCOMP); @@ -1650,8 +1650,7 @@ doface (struct mcomp *c1) cp = dp, len = j; } else { - if ((cp = malloc ((unsigned) i)) == NULL) - adios (NULL, "unable to allocate face storage"); + cp = mh_xmalloc ((unsigned) i); memcpy(cp, buffer, i); len = i; } diff --git a/uip/mhn.c b/uip/mhn.c index 55f06c4..27ee05b 100644 --- a/uip/mhn.c +++ b/uip/mhn.c @@ -242,8 +242,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhparse.c b/uip/mhparse.c index c57e745..fc24f5e 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include @@ -584,8 +585,7 @@ add_header (CT ct, char *name, char *value) HF hp; /* allocate header field structure */ - if (!(hp = malloc (sizeof(*hp)))) - adios (NULL, "out of memory"); + hp = mh_xmalloc (sizeof(*hp)); /* link data into header structure */ hp->name = name; @@ -1303,8 +1303,7 @@ invalid_param: goto no_body; } - if ((e->eb_body = bp = malloc ((unsigned) size)) == NULL) - adios (NULL, "out of memory"); + e->eb_body = bp = mh_xmalloc ((unsigned) size); fseek (p->c_fp, p->c_begin, SEEK_SET); while (size > 0) switch (cc = fread (bp, sizeof(*bp), size, p->c_fp)) { diff --git a/uip/mhpath.c b/uip/mhpath.c index d3dcc67..5084b03 100644 --- a/uip/mhpath.c +++ b/uip/mhpath.c @@ -10,6 +10,7 @@ */ #include +#include static struct swit switches[] = { #define VERSIONSW 0 @@ -52,8 +53,7 @@ main(int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhshow.c b/uip/mhshow.c index 65f66f4..c61e917 100644 --- a/uip/mhshow.c +++ b/uip/mhshow.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include @@ -169,8 +170,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhstore.c b/uip/mhstore.c index 1529de9..518a304 100644 --- a/uip/mhstore.c +++ b/uip/mhstore.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include @@ -147,8 +148,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mhtest.c b/uip/mhtest.c index 46c86ac..9219839 100644 --- a/uip/mhtest.c +++ b/uip/mhtest.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_WAIT_H # include @@ -149,8 +150,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/mshcmds.c b/uip/mshcmds.c index 4566029..63ee99c 100644 --- a/uip/mshcmds.c +++ b/uip/mshcmds.c @@ -21,6 +21,7 @@ #include #include #include +#include static char delim3[] = "-------"; /* from burst.c */ @@ -2160,8 +2161,7 @@ scancmd (char **args) if (*dp == '\\' || *dp == '"' || *dp == '\n') i++; i++; - if ((ep = malloc ((unsigned) i)) == NULL) - adios (NULL, "out of memory"); + ep = mh_xmalloc ((unsigned) i); for (dp = nfs, fp = ep; *dp; dp++) { if (*dp == '\n') { *fp++ = '\\', *fp++ = 'n'; diff --git a/uip/packf.c b/uip/packf.c index 405a005..9f71b92 100644 --- a/uip/packf.c +++ b/uip/packf.c @@ -12,6 +12,7 @@ #include #include #include +#include #include /* @@ -67,8 +68,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/pick.c b/uip/pick.c index 9f4bf0f..4f26bb2 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -12,6 +12,7 @@ #include #include #include +#include /* * We allocate space for messages (msgs array) @@ -103,8 +104,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); while ((cp = *argp++)) { if (*cp == '-') { diff --git a/uip/popi.c b/uip/popi.c index e26e346..ef11a4a 100644 --- a/uip/popi.c +++ b/uip/popi.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #ifndef RPOP @@ -402,8 +403,7 @@ popi (void) if (*dp == '\\' || *dp == '"' || *dp == '\n') i++; i++; - if ((ep = malloc ((unsigned) i)) == NULL) - adios (NULL, "out of memory"); + ep = mh_xmalloc ((unsigned) i); for (dp = nfs, fp = ep; *dp; dp++) { if (*dp == '\n') { *fp++ = '\\', *fp++ = 'n'; diff --git a/uip/popsbr.c b/uip/popsbr.c index e7ea911..d1bbafc 100644 --- a/uip/popsbr.c +++ b/uip/popsbr.c @@ -9,6 +9,7 @@ */ #include +#include extern int client(char *args, char *protocol, char *service, int rproto, char *response, int len_response); @@ -432,10 +433,7 @@ sasl_get_pass(sasl_conn_t *conn, void *context, int id, sasl_secret_t **psecret) len = strlen(pass); - *psecret = (sasl_secret_t *) malloc(sizeof(sasl_secret_t) + len); - - if (! *psecret) - return SASL_NOMEM; + *psecret = (sasl_secret_t *) mh_xmalloc(sizeof(sasl_secret_t) + len); (*psecret)->len = len; strcpy((char *) (*psecret)->data, pass); @@ -476,8 +474,8 @@ parse_proxy(char *proxy, char *host) } /* put together list of arguments */ - p = pargv = malloc(pargc * sizeof(char *)); - c = *pargv = malloc(plen * sizeof(char)); + p = pargv = mh_xmalloc(pargc * sizeof(char *)); + c = *pargv = mh_xmalloc(plen * sizeof(char)); for (cur = pro; *cur; cur++) { if (isspace(*cur) && cur[1] && !isspace(cur[1])) { *c++ = '\0'; diff --git a/uip/rcvdist.c b/uip/rcvdist.c index fd6f81c..c4be1b2 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -14,6 +14,7 @@ #include #include #include +#include static struct swit switches[] = { #define FORMSW 0 @@ -181,8 +182,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) *--savecomp = 0; for (i = ncomps; i--;) - if (!(*nxtbuf++ = malloc (SBUFSIZ))) - adios (NULL, "unable to allocate component buffer"); + *nxtbuf++ = mh_xmalloc (SBUFSIZ); nxtbuf = compbuffers; tmpbuf = *nxtbuf++; @@ -248,7 +248,7 @@ rcvdistout (FILE *inb, char *form, char *addrs) finished: ; i = format_len + char_read + 256; - scanl = malloc ((size_t) i + 2); + scanl = mh_xmalloc ((size_t) i + 2); dat[0] = dat[1] = dat[2] = dat[4] = 0; dat[3] = outputlinelen; fmt_scan (fmt, scanl, i, dat); diff --git a/uip/refile.c b/uip/refile.c index f3c6d1f..4d91291 100644 --- a/uip/refile.c +++ b/uip/refile.c @@ -11,6 +11,7 @@ */ #include +#include #include #include @@ -97,8 +98,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/replsbr.c b/uip/replsbr.c index 0b0ba6e..d92fade 100644 --- a/uip/replsbr.c +++ b/uip/replsbr.c @@ -12,6 +12,7 @@ #include #include #include +#include #include /* L_SET */ #include @@ -104,8 +105,7 @@ replout (FILE *inb, char *msg, char *drft, struct msgs *mp, int outputlinelen, *--savecomp = NULL; /* point at zero'd end minus 1 */ for (i = ncomps; i--; ) - if (!(*nxtbuf++ = malloc(SBUFSIZ))) - adios (NULL, "unable to allocate component buffer"); + *nxtbuf++ = mh_xmalloc(SBUFSIZ); nxtbuf = compbuffers; /* point at start */ tmpbuf = *nxtbuf++; @@ -230,7 +230,7 @@ finished: } } i = format_len + char_read + 256; - scanl = malloc ((size_t) i + 2); + scanl = mh_xmalloc ((size_t) i + 2); dat[0] = 0; dat[1] = 0; dat[2] = 0; @@ -324,9 +324,7 @@ formataddr (char *orig, char *str) /* if we don't have a buffer yet, get one */ if (bufsiz == 0) { - buf = malloc (BUFINCR); - if (! buf) - adios (NULL, "formataddr: couldn't allocate buffer space"); + buf = mh_xmalloc (BUFINCR); last_dst = buf; /* XXX */ bufsiz = BUFINCR - 6; /* leave some slop */ bufend = buf + bufsiz; diff --git a/uip/rmm.c b/uip/rmm.c index 072097a..b25f083 100644 --- a/uip/rmm.c +++ b/uip/rmm.c @@ -10,6 +10,7 @@ */ #include +#include /* * We allocate space for message names and ranges @@ -56,8 +57,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* parse arguments */ while ((cp = *argp++)) { diff --git a/uip/scan.c b/uip/scan.c index 02621dc..3b56830 100644 --- a/uip/scan.c +++ b/uip/scan.c @@ -14,6 +14,7 @@ #include #include #include +#include #include /* @@ -96,8 +97,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments diff --git a/uip/scansbr.c b/uip/scansbr.c index be68bf8..b178e75 100644 --- a/uip/scansbr.c +++ b/uip/scansbr.c @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef _FSTDIO # define _ptr _p /* Gag */ @@ -96,8 +97,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, width = MAXSCANL; } dat[3] = slwidth = width; - if ((scanl = (char *) malloc((size_t) (slwidth + 2) )) == NULL) - adios (NULL, "unable to malloc scan line (%d bytes)", slwidth+2); + scanl = (char *) mh_xmalloc((size_t) (slwidth + 2) ); if (outnum) umask(~m_gmprot()); @@ -133,8 +133,7 @@ scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg, used_buf += ncomps+1; *--used_buf = 0; rlwidth = bodycomp && (width > SBUFSIZ) ? width : SBUFSIZ; for (i = ncomps; i--; ) - if ((*nxtbuf++ = malloc(rlwidth)) == NULL) - adios (NULL, "unable to allocate component buffer"); + *nxtbuf++ = mh_xmalloc(rlwidth); } /* diff --git a/uip/sendsbr.c b/uip/sendsbr.c index fae91b3..81ddaf7 100644 --- a/uip/sendsbr.c +++ b/uip/sendsbr.c @@ -15,6 +15,7 @@ #include #include #include +#include #ifdef TIME_WITH_SYS_TIME # include @@ -208,8 +209,7 @@ attach(char *attachment_header_field_name, char *draft_file_name) * This buffer might need to be quite large, so we grow it as needed. */ - if ((field = (char *)malloc(field_size = 256)) == (char *)0) - adios(NULL, "can't allocate field buffer."); + field = (char *)mh_xmalloc(field_size = 256); /* * Scan the draft file for a header field name that matches the -attach diff --git a/uip/sortm.c b/uip/sortm.c index 4b8048f..92304dc 100644 --- a/uip/sortm.c +++ b/uip/sortm.c @@ -11,6 +11,7 @@ #include #include +#include /* * We allocate space for messages (msgs array) @@ -99,8 +100,7 @@ main (int argc, char **argv) */ nummsgs = 0; maxmsgs = MAXMSGS; - if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs))))) - adios (NULL, "unable to allocate storage"); + msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs))); /* * Parse arguments @@ -223,9 +223,7 @@ main (int argc, char **argv) /* * sort a list of pointers to our "messages to be sorted". */ - dlist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*dlist)); - if (! dlist) - adios (NULL, "couldn't allocate sort memory"); + dlist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*dlist)); for (i = 0; i < nmsgs; i++) dlist[i] = &smsgs[i]; dlist[nmsgs] = 0; @@ -252,9 +250,7 @@ main (int argc, char **argv) struct smsg **slist, **flist; register struct smsg ***il, **fp, **dp; - slist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*slist)); - if (! slist) - adios (NULL, "couldn't allocate sort memory"); + slist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*slist)); memcpy((char *)slist, (char *)dlist, (nmsgs+1)*sizeof(*slist)); qsort((char *)slist, nmsgs, sizeof(*slist), (qsort_comp) subsort); @@ -272,9 +268,7 @@ main (int argc, char **argv) * make up the final list, chronological but with * all the same subjects grouped together. */ - flist = (struct smsg **) malloc ((nmsgs+1) * sizeof(*flist)); - if (! flist) - adios (NULL, "couldn't allocate msg list"); + flist = (struct smsg **) mh_xmalloc ((nmsgs+1) * sizeof(*flist)); fp = flist; for (dp = dlist; *dp;) { register struct smsg **s = il[(*dp++)->s_msg]; diff --git a/uip/vmhsbr.c b/uip/vmhsbr.c index 8ee1e49..a504220 100644 --- a/uip/vmhsbr.c +++ b/uip/vmhsbr.c @@ -16,6 +16,7 @@ #include #include +#include #include static char *types[] = { @@ -98,8 +99,7 @@ peer2rc (struct record *rc) if (read (PEERrfd, (char *) rc_head (rc), RHSIZE (rc)) != RHSIZE (rc)) return rclose (rc, "read from peer lost(1)"); if (rc->rc_len) { - if ((rc->rc_data = malloc ((unsigned) rc->rc_len + 1)) == NULL) - return rclose (rc, "malloc of %d lost", rc->rc_len + 1); + rc->rc_data = mh_xmalloc ((unsigned) rc->rc_len + 1); if (read (PEERrfd, rc->rc_data, rc->rc_len) != rc->rc_len) return rclose (rc, "read from peer lost(2)"); rc->rc_data[rc->rc_len] = 0; diff --git a/uip/whatnowsbr.c b/uip/whatnowsbr.c index 1935384..d863b5b 100644 --- a/uip/whatnowsbr.c +++ b/uip/whatnowsbr.c @@ -44,6 +44,7 @@ #include #include #include +#include static struct swit whatnowswitches[] = { #define DFOLDSW 0 @@ -843,8 +844,7 @@ buildfile (char **argp, char *file) while (argp[i]) i++; } - if ((args = (char **) malloc((i + 2) * sizeof(char *))) == NULL) - adios (NULL, "unable to malloc memory"); + args = (char **) mh_xmalloc((i + 2) * sizeof(char *)); /* * For backward compatibility, we need to add -build -- 1.7.10.4