From 1f3c6bc09c7ac1a990c1639f63d5bd14a829b903 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Thu, 21 Nov 2019 11:59:23 +0100 Subject: libarptc: Simplify alloc_handle by using calloc() No need to explicitly set fields to zero when using calloc(). Acked-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- libarptc/libarptc_incl.c | 11 +++-------- 1 file 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; } -- cgit v1.2.3