Use calloc() instead of zeroing the memory our own.

This commit is contained in:
Xin LI 2006-06-07 01:43:26 +00:00
parent c84efdca04
commit 5f17c1e2b2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=159362
4 changed files with 11 additions and 22 deletions

View File

@ -154,8 +154,7 @@ Config_spec:
CPU Save_id
= {
struct cputype *cp =
(struct cputype *)malloc(sizeof (struct cputype));
memset(cp, 0, sizeof(*cp));
(struct cputype *)calloc(1, sizeof (struct cputype));
cp->cpu_name = $2;
SLIST_INSERT_HEAD(&cputype, cp, cpu_next);
} |
@ -336,8 +335,7 @@ newfile(char *name)
{
struct files_name *nl;
nl = (struct files_name *) malloc(sizeof *nl);
bzero(nl, sizeof *nl);
nl = (struct files_name *) calloc(1, sizeof *nl);
nl->f_name = name;
STAILQ_INSERT_TAIL(&fntab, nl, f_next);
}
@ -370,8 +368,7 @@ newdev(char *name)
return;
}
np = (struct device *) malloc(sizeof *np);
memset(np, 0, sizeof(*np));
np = (struct device *) calloc(1, sizeof *np);
np->d_name = name;
STAILQ_INSERT_TAIL(&dtab, np, d_next);
}
@ -420,8 +417,7 @@ newopt(struct opt_head *list, char *name, char *value)
return;
}
op = (struct opt *)malloc(sizeof (struct opt));
memset(op, 0, sizeof(*op));
op = (struct opt *)calloc(1, sizeof (struct opt));
op->op_name = name;
op->op_ownfile = 0;
op->op_value = value;

View File

@ -518,8 +518,7 @@ remember(const char *file)
return;
}
}
hl = malloc(sizeof(*hl));
bzero(hl, sizeof(*hl));
hl = calloc(1, sizeof(*hl));
hl->h_name = s;
hl->h_next = htab;
htab = hl;

View File

@ -97,8 +97,7 @@ new_fent(void)
{
struct file_list *fp;
fp = (struct file_list *) malloc(sizeof *fp);
bzero(fp, sizeof *fp);
fp = (struct file_list *) calloc(1, sizeof *fp);
STAILQ_INSERT_TAIL(&ftab, fp, f_next);
return (fp);
}

View File

@ -69,8 +69,7 @@ options(void)
/* Fake the cpu types as options. */
SLIST_FOREACH(cp, &cputype, cpu_next) {
op = (struct opt *)malloc(sizeof(*op));
memset(op, 0, sizeof(*op));
op = (struct opt *)calloc(1, sizeof(*op));
op->op_name = ns(cp->cpu_name);
SLIST_INSERT_HEAD(&opt, op, op_next);
}
@ -84,8 +83,7 @@ options(void)
printf("warning: maxusers > %d (%d)\n", users.u_max, maxusers);
/* Fake MAXUSERS as an option. */
op = (struct opt *)malloc(sizeof(*op));
memset(op, 0, sizeof(*op));
op = (struct opt *)calloc(1, sizeof(*op));
op->op_name = ns("MAXUSERS");
snprintf(buf, sizeof(buf), "%d", maxusers);
op->op_value = ns(buf);
@ -200,8 +198,7 @@ do_option(char *name)
inw, basefile, ol->o_file);
tidy++;
} else {
op = (struct opt *) malloc(sizeof *op);
bzero(op, sizeof(*op));
op = (struct opt *) calloc(1, sizeof *op);
op->op_name = inw;
op->op_value = invalue;
SLIST_INSERT_HEAD(&op_head, op, op_next);
@ -227,8 +224,7 @@ do_option(char *name)
if (value && !seen) {
/* New option appears */
op = (struct opt *) malloc(sizeof *op);
bzero(op, sizeof(*op));
op = (struct opt *) calloc(1, sizeof *op);
op->op_name = ns(name);
op->op_value = value ? ns(value) : NULL;
SLIST_INSERT_HEAD(&op_head, op, op_next);
@ -339,8 +335,7 @@ read_options(void)
}
}
po = (struct opt_list *) malloc(sizeof *po);
bzero(po, sizeof(*po));
po = (struct opt_list *) calloc(1, sizeof *po);
po->o_name = this;
po->o_file = val;
SLIST_INSERT_HEAD(&otab, po, o_next);