From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc()
Date: Thu, 21 Nov 2019 12:15:59 +0100 [thread overview]
Message-ID: <20191121111559.27066-4-phil@nwl.cc> (raw)
In-Reply-To: <20191121111559.27066-1-phil@nwl.cc>
No need to explicitly set fields to zero when using calloc().
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
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 ca23da6474990..c4d5de3f39a15 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;
}
--
2.24.0
next prev parent reply other threads:[~2019-11-21 11:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-21 11:15 [arptables PATCH 0/3] Some minor fixes Phil Sutter
2019-11-21 11:15 ` [arptables PATCH 1/3] Add .gitignore Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` [arptables PATCH 2/3] Eliminate compiler warning about size passed to strncmp() Phil Sutter
2019-11-21 13:45 ` Pablo Neira Ayuso
2019-11-21 11:15 ` Phil Sutter [this message]
2019-11-21 13:46 ` [arptables PATCH 3/3] libarptc: Simplify alloc_handle by using calloc() Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191121111559.27066-4-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).