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
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=96785
@ -601,20 +601,20 @@ c_exec(option, argvp)
|
|||||||
errx(1, "%s: no command specified", option->name);
|
errx(1, "%s: no command specified", option->name);
|
||||||
|
|
||||||
cnt = ap - *argvp + 1;
|
cnt = ap - *argvp + 1;
|
||||||
if ((new->e_argv = malloc((u_int)cnt * sizeof(char *))) == NULL)
|
if ((new->e_argv = malloc(cnt * sizeof(char *))) == NULL)
|
||||||
err(1, (char *)NULL);
|
err(1, NULL);
|
||||||
if ((new->e_orig = malloc((u_int)cnt * sizeof(char *))) == NULL)
|
if ((new->e_orig = malloc(cnt * sizeof(char *))) == NULL)
|
||||||
err(1, (char *)NULL);
|
err(1, NULL);
|
||||||
if ((new->e_len = malloc((u_int)cnt * sizeof(int))) == NULL)
|
if ((new->e_len = malloc(cnt * sizeof(int))) == NULL)
|
||||||
err(1, (char *)NULL);
|
err(1, NULL);
|
||||||
|
|
||||||
for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
|
for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) {
|
||||||
new->e_orig[cnt] = *argv;
|
new->e_orig[cnt] = *argv;
|
||||||
for (p = *argv; *p; ++p)
|
for (p = *argv; *p; ++p)
|
||||||
if (p[0] == '{' && p[1] == '}') {
|
if (p[0] == '{' && p[1] == '}') {
|
||||||
if ((new->e_argv[cnt] =
|
if ((new->e_argv[cnt] =
|
||||||
malloc((u_int)MAXPATHLEN)) == NULL)
|
malloc(MAXPATHLEN)) == NULL)
|
||||||
err(1, (char *)NULL);
|
err(1, NULL);
|
||||||
new->e_len[cnt] = MAXPATHLEN;
|
new->e_len[cnt] = MAXPATHLEN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1210,7 +1210,7 @@ f_regex(plan, entry)
|
|||||||
FTSENT *entry;
|
FTSENT *entry;
|
||||||
{
|
{
|
||||||
char *str;
|
char *str;
|
||||||
size_t len;
|
int len;
|
||||||
regex_t *pre;
|
regex_t *pre;
|
||||||
regmatch_t pmatch;
|
regmatch_t pmatch;
|
||||||
int errcode;
|
int errcode;
|
||||||
|
@ -244,7 +244,7 @@ palloc()
|
|||||||
{
|
{
|
||||||
PERSON *p;
|
PERSON *p;
|
||||||
|
|
||||||
if ((p = malloc((u_int) sizeof(PERSON))) == NULL)
|
if ((p = malloc(sizeof(PERSON))) == NULL)
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
return(p);
|
return(p);
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ walloc(pn)
|
|||||||
{
|
{
|
||||||
WHERE *w;
|
WHERE *w;
|
||||||
|
|
||||||
if ((w = malloc((u_int) sizeof(WHERE))) == NULL)
|
if ((w = malloc(sizeof(WHERE))) == NULL)
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
if (pn->whead == NULL)
|
if (pn->whead == NULL)
|
||||||
pn->whead = pn->wtail = w;
|
pn->whead = pn->wtail = w;
|
||||||
|
@ -290,7 +290,7 @@ doentry(bp)
|
|||||||
/* add new one */
|
/* add new one */
|
||||||
tt = malloc(sizeof(struct ttytab));
|
tt = malloc(sizeof(struct ttytab));
|
||||||
if (tt == NULL)
|
if (tt == NULL)
|
||||||
err(1, "malloc failure");
|
errx(1, "malloc failure");
|
||||||
tt->logout = currentout;
|
tt->logout = currentout;
|
||||||
strncpy(tt->tty, bp->ut_line, UT_LINESIZE);
|
strncpy(tt->tty, bp->ut_line, UT_LINESIZE);
|
||||||
LIST_INSERT_HEAD(&ttylist, tt, list);
|
LIST_INSERT_HEAD(&ttylist, tt, list);
|
||||||
@ -418,8 +418,8 @@ addarg(type, arg)
|
|||||||
{
|
{
|
||||||
ARG *cur;
|
ARG *cur;
|
||||||
|
|
||||||
if (!(cur = (ARG *)malloc((u_int)sizeof(ARG))))
|
if ((cur = malloc(sizeof(ARG))) == NULL)
|
||||||
err(1, "malloc failure");
|
errx(1, "malloc failure");
|
||||||
cur->next = arglist;
|
cur->next = arglist;
|
||||||
cur->type = type;
|
cur->type = type;
|
||||||
cur->name = arg;
|
cur->name = arg;
|
||||||
@ -468,8 +468,8 @@ ttyconv(arg)
|
|||||||
*/
|
*/
|
||||||
if (strlen(arg) == 2) {
|
if (strlen(arg) == 2) {
|
||||||
/* either 6 for "ttyxx" or 8 for "console" */
|
/* either 6 for "ttyxx" or 8 for "console" */
|
||||||
if (!(mval = malloc((u_int)8)))
|
if ((mval = malloc(8)) == NULL)
|
||||||
err(1, "malloc failure");
|
errx(1, "malloc failure");
|
||||||
if (!strcmp(arg, "co"))
|
if (!strcmp(arg, "co"))
|
||||||
(void)strcpy(mval, "console");
|
(void)strcpy(mval, "console");
|
||||||
else {
|
else {
|
||||||
|
@ -122,8 +122,8 @@ parallel(char **argv)
|
|||||||
char buf[_POSIX2_LINE_MAX + 1];
|
char buf[_POSIX2_LINE_MAX + 1];
|
||||||
|
|
||||||
for (cnt = 0, head = NULL; (p = *argv); ++argv, ++cnt) {
|
for (cnt = 0, head = NULL; (p = *argv); ++argv, ++cnt) {
|
||||||
if (!(lp = (LIST *)malloc((u_int)sizeof(LIST))))
|
if ((lp = malloc(sizeof(LIST))) == NULL)
|
||||||
errx(1, "%s", strerror(ENOMEM));
|
err(1, NULL);
|
||||||
if (p[0] == '-' && !p[1])
|
if (p[0] == '-' && !p[1])
|
||||||
lp->fp = stdin;
|
lp->fp = stdin;
|
||||||
else if (!(lp->fp = fopen(p, "r")))
|
else if (!(lp->fp = fopen(p, "r")))
|
||||||
|
@ -83,7 +83,7 @@ add_mapping(port, arg)
|
|||||||
char *copy, *p, *termp;
|
char *copy, *p, *termp;
|
||||||
|
|
||||||
copy = strdup(arg);
|
copy = strdup(arg);
|
||||||
mapp = malloc((u_int)sizeof(MAP));
|
mapp = malloc(sizeof(MAP));
|
||||||
if (copy == NULL || mapp == NULL)
|
if (copy == NULL || mapp == NULL)
|
||||||
errx(1, "malloc");
|
errx(1, "malloc");
|
||||||
mapp->next = NULL;
|
mapp->next = NULL;
|
||||||
|
@ -106,7 +106,7 @@ int debug, longest, quiet;
|
|||||||
void add_arc(char *, char *);
|
void add_arc(char *, char *);
|
||||||
int find_cycle(NODE *, NODE *, int, int);
|
int find_cycle(NODE *, NODE *, int, int);
|
||||||
NODE *get_node(char *);
|
NODE *get_node(char *);
|
||||||
void *grow_buf(void *, int);
|
void *grow_buf(void *, size_t);
|
||||||
void remove_node(NODE *);
|
void remove_node(NODE *);
|
||||||
void clear_cycle(void);
|
void clear_cycle(void);
|
||||||
void tsort(void);
|
void tsort(void);
|
||||||
@ -192,9 +192,9 @@ main(argc, argv)
|
|||||||
void *
|
void *
|
||||||
grow_buf(bp, size)
|
grow_buf(bp, size)
|
||||||
void *bp;
|
void *bp;
|
||||||
int size;
|
size_t size;
|
||||||
{
|
{
|
||||||
if ((bp = realloc(bp, (u_int)size)) == NULL)
|
if ((bp = realloc(bp, size)) == NULL)
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
return (bp);
|
return (bp);
|
||||||
}
|
}
|
||||||
@ -335,8 +335,8 @@ tsort()
|
|||||||
*/
|
*/
|
||||||
for (cnt = 0, n = graph; n != NULL; n = n->n_next)
|
for (cnt = 0, n = graph; n != NULL; n = n->n_next)
|
||||||
++cnt;
|
++cnt;
|
||||||
cycle_buf = malloc((u_int)sizeof(NODE *) * cnt);
|
cycle_buf = malloc(sizeof(NODE *) * cnt);
|
||||||
longest_cycle = malloc((u_int)sizeof(NODE *) * cnt);
|
longest_cycle = malloc(sizeof(NODE *) * cnt);
|
||||||
if (cycle_buf == NULL || longest_cycle == NULL)
|
if (cycle_buf == NULL || longest_cycle == NULL)
|
||||||
err(1, NULL);
|
err(1, NULL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user