mirror of
https://github.com/openbsd/src.git
synced 2024-12-22 16:42:56 -08:00
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@
This commit is contained in:
parent
a85f8ccf46
commit
cd9ca5b765
@ -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);
|
||||
}
|
||||
|
@ -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++;
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user