calling malloc.
+2006-01-01 Josh Bressers <josh@bress.net>
+
+ * patch #3966: Create a mh_xmalloc function to prevent mistakes when
+ calling malloc.
+
2005-12-24 Peter Maydell <pmaydell@chiark.greenend.org.uk>
* Bug #15285: Don't use $< in target rules in makefiles, as POSIX
--- /dev/null
+
+/*
+ * utils.h -- utility prototypes
+ *
+ * $Id$
+ */
+
+void *mh_xmalloc(size_t);
+
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
*/
#include <h/mh.h>
+#include <h/utils.h>
char *
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) {
*/
#include <h/mh.h>
+#include <h/utils.h>
/* allocate this number of pointers at a time */
#define NUMBROKEN 256
/* 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)));
}
/*
#include <h/mh.h>
#include <h/mts.h>
+#include <h/utils.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
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,
size_t len;
len = strlen(str) + 1;
- if (!(cp = malloc(len)))
- return NULL;
+ cp = mh_xmalloc(len);
memcpy (cp, str, len);
return cp;
*/
#include <h/mh.h>
+#include <h/utils.h>
char *
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);
*/
#include <h/mh.h>
+#include <h/utils.h>
/*
* Foil search of users .mh_profile
* 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"))) {
*/
#include <h/mh.h>
+#include <h/utils.h>
void
* 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);
/*
* 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);
#include <h/mh.h>
#include <h/addrsbr.h>
#include <h/fmt_scan.h>
+#include <h/utils.h>
static char *buf; /* our current working buffer */
static char *bufend; /* end of working buffer */
/* 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;
*/
#include <h/mh.h>
+#include <h/utils.h>
#define QUOTE '\\'
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");
*/
#include <h/mh.h>
+#include <h/utils.h>
#ifdef HAVE_ICONV
# include <iconv.h>
# include <errno.h>
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.
*/
#include <h/mh.h>
+#include <h/utils.h>
/* We allocate the `mi' array 1024 elements at a time */
#define NUMMSGS 1024
}
/* 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;
* 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) {
/*
* 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
*/
#include <h/mh.h>
+#include <h/utils.h>
/*
* Reallocate some of the space in the folder
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) {
*/
#include <h/mh.h>
+#include <h/utils.h>
char **
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 */
*/
#include <h/mh.h>
+#include <h/utils.h>
char *
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;
#include <h/mh.h>
#include <h/signals.h>
+#include <h/utils.h>
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
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;
#include <h/mh.h>
#include <h/mts.h>
+#include <h/utils.h>
/* 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
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;
#include <h/mf.h>
#include <ctype.h>
#include <stdio.h>
+#include <h/utils.h>
/*
* static prototypes
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;
}
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;
}
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)) {
#include <h/mh.h> /* for snprintf() */
#include <h/nmh.h>
+#include <h/utils.h>
#define nmhetcdir(file) NMHETCDIR#file
*bp = 0;
len = strlen (buffer) + 1;
- if ((bp = malloc (len)))
- memcpy (bp, buffer, len);
+ bp = mh_xmalloc (len);
+ memcpy (bp, buffer, len);
return bp;
}
*/
#include <h/mh.h>
+#include <h/utils.h>
extern char **environ;
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);
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;
*/
#include <h/mh.h>
+#include <h/utils.h>
struct procstr {
char *procname;
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);
*/
#include <h/mh.h>
+#include <h/utils.h>
#include <pwd.h>
#include <errno.h>
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;
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;
myname = tmp;
}
- *aname = malloc((size_t) strlen(myname) + 1);
+ *aname = mh_xmalloc((size_t) strlen(myname) + 1);
strcpy (*aname, myname);
}
mypass = *aname;
}
- *apass = malloc((size_t) strlen(mypass) + 1);
+ *apass = mh_xmalloc((size_t) strlen(mypass) + 1);
strcpy (*apass, mypass);
}
*/
#include <h/mh.h>
+#include <h/utils.h>
/* allocate this much buffer space at a time */
#define MAXBUFFER 1024
/* 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);
}
/*
*/
#include <h/mh.h>
+#include <h/utils.h>
char *
return NULL;
len = strlen(str) + 1;
- if (!(cp = malloc (len)))
- return NULL;
+ cp = mh_xmalloc (len);
memcpy (cp, str, len);
return cp;
}
--- /dev/null
+
+/*
+ * 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 <h/nmh.h>
+#include <h/utils.h>
+#include <stdlib.h>
+
+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;
+}
*/
#include <h/mh.h>
+#include <h/utils.h>
#define QUOTE '\\'
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) {
#include <h/mh.h>
#include <h/aliasbr.h>
+#include <h/utils.h>
#include <grp.h>
#include <pwd.h>
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;
{
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;
{
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;
*/
#include <h/mh.h>
+#include <h/utils.h>
/*
* We allocate space for messages (msgs array)
*/
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 == '-') {
#include <h/mh.h>
#include <h/tws.h>
+#include <h/utils.h>
#include <fcntl.h>
#include <errno.h>
#include <utime.h>
* 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.
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);
}
/*
#include <fcntl.h>
#include <h/aliasbr.h>
#include <h/mts.h>
+#include <h/utils.h>
#include <grp.h>
#include <pwd.h>
/* 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 ())) {
*/
#include <h/mh.h>
+#include <h/utils.h>
#define FALSE 0
#define TRUE 1
/* 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;
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
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)));
*/
#include <h/mh.h>
+#include <h/utils.h>
#include <errno.h>
static struct swit switches[] = {
/* 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
#include <fcntl.h>
#include <h/fmt_scan.h>
#include <h/tws.h>
+#include <h/utils.h>
#define IFORMAT "digest-issue-%s"
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);
*/
#include <h/mh.h> /* mh internals */
+#include <h/utils.h>
#include <pwd.h> /* structure for getpwuid() results */
static struct swit switches[] = {
/*
* 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);
*/
#include <h/mh.h>
+#include <h/utils.h>
/*
* We allocate space for messages (msgs array)
*/
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
#include <h/tws.h>
#include <h/mime.h>
#include <h/mhparse.h>
+#include <h/utils.h>
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
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;
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)) {
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
+#include <h/utils.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
*/
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
#include <h/addrsbr.h>
#include <h/fmt_scan.h>
#include <h/tws.h>
+#include <h/utils.h>
#include <setjmp.h>
#include <signal.h>
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);
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;
}
*/
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
#include <h/tws.h>
#include <h/mime.h>
#include <h/mhparse.h>
+#include <h/utils.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
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;
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)) {
*/
#include <h/mh.h>
+#include <h/utils.h>
static struct swit switches[] = {
#define VERSIONSW 0
*/
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
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
+#include <h/utils.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
*/
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
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
+#include <h/utils.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
*/
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
#include <h/mime.h>
#include <h/mhparse.h>
#include <h/mhcachesbr.h>
+#include <h/utils.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
*/
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
#include <signal.h>
#include <h/msh.h>
#include <h/picksbr.h>
+#include <h/utils.h>
static char delim3[] = "-------"; /* from burst.c */
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';
#include <h/mh.h>
#include <fcntl.h>
#include <h/dropsbr.h>
+#include <h/utils.h>
#include <errno.h>
/*
*/
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
#include <h/mh.h>
#include <h/tws.h>
#include <h/picksbr.h>
+#include <h/utils.h>
/*
* We allocate space for messages (msgs array)
*/
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 == '-') {
#include <h/fmt_scan.h>
#include <h/scansbr.h>
#include <h/mts.h>
+#include <h/utils.h>
#include <errno.h>
#ifndef RPOP
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';
*/
#include <h/mh.h>
+#include <h/utils.h>
extern int client(char *args, char *protocol, char *service, int rproto,
char *response, int len_response);
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);
}
/* 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';
#include <h/rcvmail.h>
#include <h/tws.h>
#include <h/mts.h>
+#include <h/utils.h>
static struct swit switches[] = {
#define FORMSW 0
*--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++;
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);
*/
#include <h/mh.h>
+#include <h/utils.h>
#include <fcntl.h>
#include <errno.h>
*/
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
#include <h/mh.h>
#include <h/addrsbr.h>
#include <h/fmt_scan.h>
+#include <h/utils.h>
#include <sys/file.h> /* L_SET */
#include <errno.h>
*--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++;
}
}
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;
/* 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;
*/
#include <h/mh.h>
+#include <h/utils.h>
/*
* We allocate space for message names and ranges
*/
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++)) {
#include <h/scansbr.h>
#include <h/tws.h>
#include <h/mts.h>
+#include <h/utils.h>
#include <errno.h>
/*
*/
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
#include <h/fmt_scan.h>
#include <h/scansbr.h>
#include <h/tws.h>
+#include <h/utils.h>
#ifdef _FSTDIO
# define _ptr _p /* Gag */
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());
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);
}
/*
#include <signal.h>
#include <fcntl.h>
#include <h/mime.h>
+#include <h/utils.h>
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
* 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
#include <h/mh.h>
#include <h/tws.h>
+#include <h/utils.h>
/*
* We allocate space for messages (msgs array)
*/
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
/*
* 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;
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);
* 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];
#include <h/mh.h>
#include <h/vmhsbr.h>
+#include <h/utils.h>
#include <errno.h>
static char *types[] = {
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;
#include <fcntl.h>
#include <signal.h>
#include <h/mime.h>
+#include <h/utils.h>
static struct swit whatnowswitches[] = {
#define DFOLDSW 0
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