return f;
noexist:
- f = malloc(sizeof(*f));
+ f = calloc(1, sizeof(*f));
if (f) {
- memset(f, 0, sizeof(*f));
strncpy(f->name, str, 15);
f->parse_genlopt = parse_nofopt;
f->print_genlopt = print_nofopt;
{
struct db_names *db;
- db = malloc(sizeof(*db));
+ db = calloc(1, sizeof(*db));
if (!db)
return NULL;
- memset(db, 0, sizeof(*db));
-
db->size = MAX_ENTRIES;
- db->hash = malloc(sizeof(struct db_entry *) * db->size);
- memset(db->hash, 0, sizeof(struct db_entry *) * db->size);
+ db->hash = calloc(db->size, sizeof(struct db_entry *));
return db;
}
static struct table_hdr th;
int ofs = 0;
- for (i = 0; i < HDR_LINES; i++) {
- th.hdr[i] = malloc(HDR_LINE_LENGTH);
- memset(th.hdr[i], 0, HDR_LINE_LENGTH);
- }
+ for (i = 0; i < HDR_LINES; i++)
+ th.hdr[i] = calloc(1, HDR_LINE_LENGTH);
for (i = 0; i < fps->num; i++) {
char *cname, *fname = fps->params[i].lf->name;
struct lnstat_file *lf;
/* allocate */
- lf = malloc(sizeof(*lf));
+ lf = calloc(1, sizeof(*lf));
if (!lf) {
fprintf(stderr, "out of memory\n");
return NULL;
}
/* initialize */
- memset(lf, 0, sizeof(*lf));
-
/* de->d_name is guaranteed to be <= NAME_MAX */
strcpy(lf->basename, file);
strcpy(lf->path, path);
if (args == NULL)
return PARSE_ERR(args, "canid: missing arguments");
- rules.rules_raw = malloc(sizeof(struct can_filter) * rules.rules_capacity);
- memset(rules.rules_raw, 0, sizeof(struct can_filter) * rules.rules_capacity);
+ rules.rules_raw = calloc(rules.rules_capacity,
+ sizeof(struct can_filter));
do {
if (!bstrcmp(args, "sff")) {
goto restart_s;
}
#endif
- a = malloc(sizeof(*a));
+ a = calloc(1, sizeof(*a));
if (a) {
- memset(a, 0, sizeof(*a));
strncpy(a->id, "noact", 15);
a->parse_aopt = parse_noaopt;
a->print_aopt = print_noaopt;
return NULL;
#endif
- new_name = malloc(strlen(name) + 1);
- lname = malloc(strlen(name) + 1);
- if (new_name)
- memset(new_name, '\0', strlen(name) + 1);
- else
+ new_name = calloc(1, strlen(name) + 1);
+ lname = calloc(1, strlen(name) + 1);
+ if (!new_name)
exit_error(PARAMETER_PROBLEM, "get_target_name");
-
- if (lname)
- memset(lname, '\0', strlen(name) + 1);
- else
+ if (!lname)
exit_error(PARAMETER_PROBLEM, "get_target_name");
strcpy(new_name, name);
return p;
noexist:
- p = malloc(sizeof(*p));
+ p = calloc(1, sizeof(*p));
if (p) {
- memset(p, 0, sizeof(*p));
strncpy(p->id, str, sizeof(p->id) - 1);
p->parse_peopt = pedit_parse_nopopt;
goto reg;
return q;
noexist:
- q = malloc(sizeof(*q));
+ q = calloc(1, sizeof(*q));
if (q) {
-
- memset(q, 0, sizeof(*q));
- q->id = strcpy(malloc(strlen(str)+1), str);
+ q->id = strdup(str);
q->parse_qopt = parse_noqopt;
q->print_qopt = print_noqopt;
goto reg;
filter_list = q;
return q;
noexist:
- q = malloc(sizeof(*q));
+ q = calloc(1, sizeof(*q));
if (q) {
- memset(q, 0, sizeof(*q));
strncpy(q->id, str, 15);
q->parse_fopt = parse_nofopt;
q->print_fopt = print_nofopt;
FILE *fp;
tmp_len = sizeof("4096,") + BPF_MAXINSNS * op_len;
- tmp_string = malloc(tmp_len);
+ tmp_string = calloc(1, tmp_len);
if (tmp_string == NULL)
return -ENOMEM;
- memset(tmp_string, 0, tmp_len);
-
fp = fopen(arg, "r");
if (fp == NULL) {
perror("Cannot fopen");
static void graph_node_add(__u32 parent_id, __u32 id, void *data,
int len)
{
- struct graph_node *node = malloc(sizeof(struct graph_node));
+ struct graph_node *node = calloc(1, sizeof(struct graph_node));
- memset(node, 0, sizeof(*node));
node->id = id;
node->parent_id = parent_id;
return eu;
noexist:
- eu = malloc(sizeof(*eu));
+ eu = calloc(1, sizeof(*eu));
if (eu) {
- memset(eu, 0, sizeof(*eu));
strncpy(eu->id, name, sizeof(eu->id) - 1);
eu->parse_eopt = parse_noeopt;
goto reg;