diff options
author | mmcc <mmcc@cvs.openbsd.org> | 2015-10-16 17:56:08 +0000 |
---|---|---|
committer | mmcc <mmcc@cvs.openbsd.org> | 2015-10-16 17:56:08 +0000 |
commit | a15c321a70fe169b83f8a2454677a1d1196ad773 (patch) | |
tree | ad30c0d192d679a9716078547f224645f9f71651 /usr.bin | |
parent | f714cdb6c71ef2763108a2cc525ab35950418074 (diff) |
Modernize allocation by:
* removing unneeded casts of void* return values
* replacing varied and creative error messages with the allocation
function's name
* replacing errx() with err() so that the errno string is reported
ok beck@, jung@, millert@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mail/aux.c | 8 | ||||
-rw-r--r-- | usr.bin/mail/cmd2.c | 8 | ||||
-rw-r--r-- | usr.bin/mail/cmd3.c | 16 | ||||
-rw-r--r-- | usr.bin/mail/fio.c | 7 | ||||
-rw-r--r-- | usr.bin/mail/lex.c | 4 | ||||
-rw-r--r-- | usr.bin/mail/list.c | 8 | ||||
-rw-r--r-- | usr.bin/mail/names.c | 6 | ||||
-rw-r--r-- | usr.bin/mail/popen.c | 10 | ||||
-rw-r--r-- | usr.bin/mail/strings.c | 6 | ||||
-rw-r--r-- | usr.bin/mail/temp.c | 4 | ||||
-rw-r--r-- | usr.bin/mail/vars.c | 8 |
11 files changed, 42 insertions, 43 deletions
diff --git a/usr.bin/mail/aux.c b/usr.bin/mail/aux.c index a6987a1eb2e..830be426c69 100644 --- a/usr.bin/mail/aux.c +++ b/usr.bin/mail/aux.c @@ -1,4 +1,4 @@ -/* $OpenBSD: aux.c,v 1.28 2015/10/13 08:49:51 guenther Exp $ */ +/* $OpenBSD: aux.c,v 1.29 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: aux.c,v 1.5 1997/05/13 06:15:52 mikel Exp $ */ /* @@ -417,8 +417,8 @@ skin(char *name) return(name); /* We assume that length(input) <= length(output) */ - if ((nbuf = (char *)malloc(strlen(name) + 1)) == NULL) - errx(1, "Out of memory"); + if ((nbuf = malloc(strlen(name) + 1)) == NULL) + err(1, "malloc"); gotlt = 0; lastsp = 0; bufend = nbuf; @@ -502,7 +502,7 @@ skin(char *name) } *cp2 = 0; - if ((cp = (char *)realloc(nbuf, strlen(nbuf) + 1)) != NULL) + if ((cp = realloc(nbuf, strlen(nbuf) + 1)) != NULL) nbuf = cp; return(nbuf); } diff --git a/usr.bin/mail/cmd2.c b/usr.bin/mail/cmd2.c index 53fa175972c..54b30bc153c 100644 --- a/usr.bin/mail/cmd2.c +++ b/usr.bin/mail/cmd2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd2.c,v 1.21 2014/03/16 18:38:30 guenther Exp $ */ +/* $OpenBSD: cmd2.c,v 1.22 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: cmd2.c,v 1.7 1997/05/17 19:55:10 pk Exp $ */ /* @@ -392,12 +392,12 @@ ignore1(char **list, struct ignoretab *tab, char *which) if (member(field, tab)) continue; h = hash(field); - igp = (struct ignore *)calloc(1, sizeof(struct ignore)); + igp = calloc(1, sizeof(struct ignore)); if (igp == NULL) - errx(1, "Out of memory"); + err(1, "calloc"); igp->i_field = strdup(field); if (igp->i_field == NULL) - errx(1, "Out of memory"); + err(1, "strdup"); igp->i_link = tab->i_head[h]; tab->i_head[h] = igp; tab->i_count++; diff --git a/usr.bin/mail/cmd3.c b/usr.bin/mail/cmd3.c index 7bdfce32623..c30d9d91b55 100644 --- a/usr.bin/mail/cmd3.c +++ b/usr.bin/mail/cmd3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd3.c,v 1.26 2015/01/20 16:59:07 millert Exp $ */ +/* $OpenBSD: cmd3.c,v 1.27 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: cmd3.c,v 1.8 1997/07/09 05:29:49 mikel Exp $ */ /* @@ -478,8 +478,8 @@ group(void *v) gname = *argv; h = hash(gname); if ((gh = findgroup(gname)) == NULL) { - if ((gh = (struct grouphead *)calloc(1, sizeof(*gh))) == NULL) - errx(1, "Out of memory"); + if ((gh = calloc(1, sizeof(*gh))) == NULL) + err(1, "calloc"); gh->g_name = vcopy(gname); gh->g_list = NULL; gh->g_link = groups[h]; @@ -493,8 +493,8 @@ group(void *v) */ for (ap = argv+1; *ap != NULL; ap++) { - if ((gp = (struct group *)calloc(1, sizeof(*gp))) == NULL) - errx(1, "Out of memory"); + if ((gp = calloc(1, sizeof(*gp))) == NULL) + err(1, "calloc"); gp->ge_name = vcopy(*ap); gp->ge_link = gh->g_list; gh->g_list = gp; @@ -725,11 +725,11 @@ alternates(void *v) } if (altnames != 0) (void)free(altnames); - if ((altnames = (char **)calloc(c, sizeof(char *))) == NULL) - errx(1, "Out of memory"); + if ((altnames = calloc(c, sizeof(char *))) == NULL) + err(1, "calloc"); for (ap = namelist, ap2 = altnames; *ap; ap++, ap2++) { if ((*ap2 = strdup(*ap)) == NULL) - errx(1, "Out of memory"); + err(1, "strdup"); } *ap2 = 0; return(0); diff --git a/usr.bin/mail/fio.c b/usr.bin/mail/fio.c index fef47870ed2..a10545f77cc 100644 --- a/usr.bin/mail/fio.c +++ b/usr.bin/mail/fio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fio.c,v 1.34 2014/12/16 18:31:06 millert Exp $ */ +/* $OpenBSD: fio.c,v 1.35 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: fio.c,v 1.8 1997/07/07 22:57:55 phil Exp $ */ /* @@ -278,10 +278,9 @@ makemessage(FILE *f, int omsgCount) struct message *nmessage; size = (msgCount + 1) * sizeof(struct message); - nmessage = (struct message *)realloc(message, size); + nmessage = realloc(message, size); if (nmessage == 0) - errx(1, "Insufficient memory for %d messages", - msgCount); + err(1, "realloc"); if (omsgCount == 0 || message == NULL) dot = nmessage; else diff --git a/usr.bin/mail/lex.c b/usr.bin/mail/lex.c index d226929a752..2ad3ea3a898 100644 --- a/usr.bin/mail/lex.c +++ b/usr.bin/mail/lex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lex.c,v 1.38 2014/10/26 20:38:13 guenther Exp $ */ +/* $OpenBSD: lex.c,v 1.39 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */ /* @@ -528,7 +528,7 @@ setmsize(int n) msize = (n + 1) * sizeof(*msgvec); if ((msgvec2 = realloc(msgvec, msize)) == NULL) - errx(1, "Out of memory"); + err(1, "realloc"); msgvec = msgvec2; memset(msgvec, 0, msize); } diff --git a/usr.bin/mail/list.c b/usr.bin/mail/list.c index 6be696f72bf..c870b9be9e7 100644 --- a/usr.bin/mail/list.c +++ b/usr.bin/mail/list.c @@ -1,4 +1,4 @@ -/* $OpenBSD: list.c,v 1.19 2014/01/17 18:42:30 okan Exp $ */ +/* $OpenBSD: list.c,v 1.20 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: list.c,v 1.7 1997/07/09 05:23:36 mikel Exp $ */ /* @@ -377,8 +377,8 @@ getrawlist(char *line, char **argv, int argc) char *linebuf, *linebuf2; size_t newsize, linebufsize = BUFSIZ; - if ((linebuf = (char *)malloc(linebufsize)) == NULL) - errx(1, "Out of memory"); + if ((linebuf = malloc(linebufsize)) == NULL) + err(1, "malloc"); argn = 0; cp = line; @@ -399,7 +399,7 @@ getrawlist(char *line, char **argv, int argc) newsize = linebufsize + BUFSIZ; linebuf2 = realloc(linebuf, newsize); if (linebuf2 == NULL) - errx(1, "Out of memory"); + err(1, "realloc"); linebuf = linebuf2; linebufsize = newsize; cp2 = linebuf + linebufsize - BUFSIZ - 1; diff --git a/usr.bin/mail/names.c b/usr.bin/mail/names.c index c61640eec57..5562070c736 100644 --- a/usr.bin/mail/names.c +++ b/usr.bin/mail/names.c @@ -1,4 +1,4 @@ -/* $OpenBSD: names.c,v 1.22 2015/01/20 16:59:07 millert Exp $ */ +/* $OpenBSD: names.c,v 1.23 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: names.c,v 1.5 1996/06/08 19:48:32 christos Exp $ */ /* @@ -88,8 +88,8 @@ extract(char *line, int ntype) if (line == NULL || *line == '\0') return(NULL); - if ((nbuf = (char *)malloc(strlen(line) + 1)) == NULL) - errx(1, "Out of memory"); + if ((nbuf = malloc(strlen(line) + 1)) == NULL) + err(1, "malloc"); top = NULL; np = NULL; cp = line; diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c index 2ce59fe2e8d..b6299a54637 100644 --- a/usr.bin/mail/popen.c +++ b/usr.bin/mail/popen.c @@ -1,4 +1,4 @@ -/* $OpenBSD: popen.c,v 1.37 2015/01/16 06:40:09 deraadt Exp $ */ +/* $OpenBSD: popen.c,v 1.38 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* @@ -162,8 +162,8 @@ register_file(FILE *fp, int pipe, pid_t pid) { struct fp *fpp; - if ((fpp = (struct fp *)malloc(sizeof(*fpp))) == NULL) - errx(1, "Out of memory"); + if ((fpp = malloc(sizeof(*fpp))) == NULL) + err(1, "malloc"); fpp->fp = fp; fpp->pipe = pipe; fpp->pid = pid; @@ -313,9 +313,9 @@ findchild(pid_t pid, int dont_alloc) *cpp = child_freelist; child_freelist = (*cpp)->link; } else { - *cpp = (struct child *)malloc(sizeof(struct child)); + *cpp = malloc(sizeof(struct child)); if (*cpp == NULL) - errx(1, "Out of memory"); + err(1, "malloc"); } (*cpp)->pid = pid; (*cpp)->done = (*cpp)->free = 0; diff --git a/usr.bin/mail/strings.c b/usr.bin/mail/strings.c index 090e34c6188..245e7d85189 100644 --- a/usr.bin/mail/strings.c +++ b/usr.bin/mail/strings.c @@ -1,4 +1,4 @@ -/* $OpenBSD: strings.c,v 1.9 2009/10/27 23:59:40 deraadt Exp $ */ +/* $OpenBSD: strings.c,v 1.10 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: strings.c,v 1.5 1996/06/08 19:48:40 christos Exp $ */ /* @@ -71,9 +71,9 @@ salloc(int size) errx(1, "String too large"); if (sp->s_topFree == NULL) { index = sp - &stringdope[0]; - sp->s_topFree = (char *)malloc(STRINGSIZE << index); + sp->s_topFree = malloc(STRINGSIZE << index); if (sp->s_topFree == NULL) - errx(1, "No room for space %d", index); + err(1, "malloc"); sp->s_nextFree = sp->s_topFree; sp->s_nleft = STRINGSIZE << index; } diff --git a/usr.bin/mail/temp.c b/usr.bin/mail/temp.c index 2b9d224a862..e3c88b2c7d3 100644 --- a/usr.bin/mail/temp.c +++ b/usr.bin/mail/temp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: temp.c,v 1.15 2009/10/27 23:59:40 deraadt Exp $ */ +/* $OpenBSD: temp.c,v 1.16 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: temp.c,v 1.5 1996/06/08 19:48:42 christos Exp $ */ /* @@ -49,7 +49,7 @@ tinit(void) if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0') tmpdir = _PATH_TMP; if ((tmpdir = strdup(tmpdir)) == NULL) - errx(1, "Out of memory"); + err(1, "strdup"); /* Strip trailing '/' if necessary */ cp = tmpdir + strlen(tmpdir) - 1; diff --git a/usr.bin/mail/vars.c b/usr.bin/mail/vars.c index 7f2fe5dda19..2830d900908 100644 --- a/usr.bin/mail/vars.c +++ b/usr.bin/mail/vars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vars.c,v 1.12 2009/10/27 23:59:40 deraadt Exp $ */ +/* $OpenBSD: vars.c,v 1.13 2015/10/16 17:56:07 mmcc Exp $ */ /* $NetBSD: vars.c,v 1.4 1996/06/08 19:48:45 christos Exp $ */ /* @@ -51,8 +51,8 @@ assign(char *name, char *value) h = hash(name); vp = lookup(name); if (vp == NULL) { - if ((vp = (struct var *)calloc(1, sizeof(*vp))) == NULL) - errx(1, "Out of memory"); + if ((vp = calloc(1, sizeof(*vp))) == NULL) + err(1, "calloc"); vp->v_name = vcopy(name); vp->v_link = variables[h]; variables[h] = vp; @@ -87,7 +87,7 @@ vcopy(char *str) if (*str == '\0') return(""); if ((new = strdup(str)) == NULL) - errx(1, "Out of memory"); + err(1, "strdup"); return(new); } |