Clean up malloc(3)'s argument. Remove casts which do nothing when we're
using sizeof() anyway. Use slightly more consistent (per-file) error reporting for malloc(3) returning NULL. If "malloc failed" was being printed, don't use err(3). If a NULL format is being used, use err(3). In one case errx(3) was being used with strerror(3), so just use err(3).
This commit is contained in:
parent
03083777d9
commit
47bca8b02c
@ -601,20 +601,20 @@ c_exec(option, argvp)
|
||||
errx(1, "%s: no command specified", option->name);
|
||||
|
||||
cnt = ap - *argvp + 1;
|
||||
if ((new->e_argv = malloc((u_int)cnt * sizeof(char *))) == NULL)
|
||||
err(1, (char *)NULL);
|
||||
if ((new->e_orig = malloc((u_int)cnt * sizeof(char *))) == NULL)
|
||||
err(1, (char *)NULL);
|
||||
if ((new->e_len = malloc((u_int)cnt * sizeof(int))) == NULL)
|
||||
err(1, (char *)NULL);
|
||||
if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL)
|
||||
err(1, NULL);
|
||||
if ((new->e_orig = malloc(cnt * sizeof(char *))) == NULL)
|
||||
err(1, NULL);
|
||||
if ((new->e_len = malloc(cnt * sizeof(int))) == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
|
||||
new->e_orig[cnt] = *argv;
|
||||
for (p = *argv; *p; ++p)
|
||||
if (p[0] == '{' && p[1] == '}') {
|
||||
if ((new->e_argv[cnt] =
|
||||
malloc((u_int)MAXPATHLEN)) == NULL)
|
||||
err(1, (char *)NULL);
|
||||
malloc(MAXPATHLEN)) == NULL)
|
||||
err(1, NULL);
|
||||
new->e_len[cnt] = MAXPATHLEN;
|
||||
break;
|
||||
}
|
||||
@ -1210,7 +1210,7 @@ f_regex(plan, entry)
|
||||
FTSENT *entry;
|
||||
{
|
||||
char *str;
|
||||
size_t len;
|
||||
int len;
|
||||
regex_t *pre;
|
||||
regmatch_t pmatch;
|
||||
int errcode;
|
||||
|
@ -244,7 +244,7 @@ palloc()
|
||||
{
|
||||
PERSON *p;
|
||||
|
||||
if ((p = malloc((u_int) sizeof(PERSON))) == NULL)
|
||||
if ((p = malloc(sizeof(PERSON))) == NULL)
|
||||
err(1, NULL);
|
||||
return(p);
|
||||
}
|
||||
@ -255,7 +255,7 @@ walloc(pn)
|
||||
{
|
||||
WHERE *w;
|
||||
|
||||
if ((w = malloc((u_int) sizeof(WHERE))) == NULL)
|
||||
if ((w = malloc(sizeof(WHERE))) == NULL)
|
||||
err(1, NULL);
|
||||
if (pn->whead == NULL)
|
||||
pn->whead = pn->wtail = w;
|
||||
|
@ -290,7 +290,7 @@ doentry(bp)
|
||||
/* add new one */
|
||||
tt = malloc(sizeof(struct ttytab));
|
||||
if (tt == NULL)
|
||||
err(1, "malloc failure");
|
||||
errx(1, "malloc failure");
|
||||
tt->logout = currentout;
|
||||
strncpy(tt->tty, bp->ut_line, UT_LINESIZE);
|
||||
LIST_INSERT_HEAD(&ttylist, tt, list);
|
||||
@ -418,8 +418,8 @@ addarg(type, arg)
|
||||
{
|
||||
ARG *cur;
|
||||
|
||||
if (!(cur = (ARG *)malloc((u_int)sizeof(ARG))))
|
||||
err(1, "malloc failure");
|
||||
if ((cur = malloc(sizeof(ARG))) == NULL)
|
||||
errx(1, "malloc failure");
|
||||
cur->next = arglist;
|
||||
cur->type = type;
|
||||
cur->name = arg;
|
||||
@ -468,8 +468,8 @@ ttyconv(arg)
|
||||
*/
|
||||
if (strlen(arg) == 2) {
|
||||
/* either 6 for "ttyxx" or 8 for "console" */
|
||||
if (!(mval = malloc((u_int)8)))
|
||||
err(1, "malloc failure");
|
||||
if ((mval = malloc(8)) == NULL)
|
||||
errx(1, "malloc failure");
|
||||
if (!strcmp(arg, "co"))
|
||||
(void)strcpy(mval, "console");
|
||||
else {
|
||||
|
@ -122,8 +122,8 @@ parallel(char **argv)
|
||||
char buf[_POSIX2_LINE_MAX + 1];
|
||||
|
||||
for (cnt = 0, head = NULL; (p = *argv); ++argv, ++cnt) {
|
||||
if (!(lp = (LIST *)malloc((u_int)sizeof(LIST))))
|
||||
errx(1, "%s", strerror(ENOMEM));
|
||||
if ((lp = malloc(sizeof(LIST))) == NULL)
|
||||
err(1, NULL);
|
||||
if (p[0] == '-' && !p[1])
|
||||
lp->fp = stdin;
|
||||
else if (!(lp->fp = fopen(p, "r")))
|
||||
|
@ -83,7 +83,7 @@ add_mapping(port, arg)
|
||||
char *copy, *p, *termp;
|
||||
|
||||
copy = strdup(arg);
|
||||
mapp = malloc((u_int)sizeof(MAP));
|
||||
mapp = malloc(sizeof(MAP));
|
||||
if (copy == NULL || mapp == NULL)
|
||||
errx(1, "malloc");
|
||||
mapp->next = NULL;
|
||||
|
@ -106,7 +106,7 @@ int debug, longest, quiet;
|
||||
void add_arc(char *, char *);
|
||||
int find_cycle(NODE *, NODE *, int, int);
|
||||
NODE *get_node(char *);
|
||||
void *grow_buf(void *, int);
|
||||
void *grow_buf(void *, size_t);
|
||||
void remove_node(NODE *);
|
||||
void clear_cycle(void);
|
||||
void tsort(void);
|
||||
@ -192,9 +192,9 @@ main(argc, argv)
|
||||
void *
|
||||
grow_buf(bp, size)
|
||||
void *bp;
|
||||
int size;
|
||||
size_t size;
|
||||
{
|
||||
if ((bp = realloc(bp, (u_int)size)) == NULL)
|
||||
if ((bp = realloc(bp, size)) == NULL)
|
||||
err(1, NULL);
|
||||
return (bp);
|
||||
}
|
||||
@ -335,8 +335,8 @@ tsort()
|
||||
*/
|
||||
for (cnt = 0, n = graph; n != NULL; n = n->n_next)
|
||||
++cnt;
|
||||
cycle_buf = malloc((u_int)sizeof(NODE *) * cnt);
|
||||
longest_cycle = malloc((u_int)sizeof(NODE *) * cnt);
|
||||
cycle_buf = malloc(sizeof(NODE *) * cnt);
|
||||
longest_cycle = malloc(sizeof(NODE *) * cnt);
|
||||
if (cycle_buf == NULL || longest_cycle == NULL)
|
||||
err(1, NULL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user