summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-11-21 11:59:23 +0100
committerPhil Sutter <phil@nwl.cc>2019-11-21 16:48:01 +0100
commit1f3c6bc09c7ac1a990c1639f63d5bd14a829b903 (patch)
tree8732a9b73bb56ab5f106430a6c02d0780bbf65ac
parent4e5e23adaad58cded55b55b6c90aa0cbc207feb2 (diff)
libarptc: Simplify alloc_handle by using calloc()
No need to explicitly set fields to zero when using calloc(). Acked-by: Phil Sutter <phil@nwl.cc> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--libarptc/libarptc_incl.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/libarptc/libarptc_incl.c b/libarptc/libarptc_incl.c
index ca23da6..c4d5de3 100644
--- a/libarptc/libarptc_incl.c
+++ b/libarptc/libarptc_incl.c
@@ -191,21 +191,16 @@ alloc_handle(const char *tablename, unsigned int size, unsigned int num_rules)
+ size
+ num_rules * sizeof(struct counter_map);
- if ((h = malloc(len)) == NULL) {
+ if ((h = calloc(1, len)) == NULL) {
errno = ENOMEM;
return NULL;
}
- h->changed = 0;
- h->cache_num_chains = 0;
- h->cache_chain_heads = NULL;
h->counter_map = (void *)h
+ sizeof(STRUCT_TC_HANDLE)
+ size;
- strncpy(h->info.name, tablename, sizeof(h->info.name));
- h->info.name[sizeof(h->info.name)-1] = '\0';
- strncpy(h->entries.name, tablename, sizeof(h->entries.name));
- h->entries.name[sizeof(h->entries.name)-1] = '\0';
+ strncpy(h->info.name, tablename, sizeof(h->info.name) - 1);
+ strncpy(h->entries.name, tablename, sizeof(h->entries.name) - 1);
return h;
}