netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnftnl,v2 4/4] src: do not nul-terminate internal helper functions
Date: Wed,  4 Oct 2017 14:23:23 +0200	[thread overview]
Message-ID: <1507119803-15127-4-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1507119803-15127-1-git-send-email-pablo@netfilter.org>

Public API already does this for us, no need to do this again from
internal helper functions.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/chain.c         | 3 ---
 src/expr/data_reg.c | 3 ---
 src/gen.c           | 3 ---
 src/object.c        | 3 ---
 src/rule.c          | 3 ---
 src/ruleset.c       | 6 ------
 src/set.c           | 3 ---
 src/set_elem.c      | 2 --
 src/table.c         | 3 ---
 9 files changed, 29 deletions(-)

diff --git a/src/chain.c b/src/chain.c
index 5e30a8016cac..a11bcf5cba03 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -827,9 +827,6 @@ static int nftnl_chain_cmd_snprintf(char *buf, size_t size,
 {
 	int ret, remain = size, offset = 0;
 
-	if (size)
-		buf[0] = '\0';
-
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
 	SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index c925e2013c2f..a246952f7f01 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -194,9 +194,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
 			    uint32_t output_format, uint32_t flags,
 			    int reg_type)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch(reg_type) {
 	case DATA_VALUE:
 		switch(output_format) {
diff --git a/src/gen.c b/src/gen.c
index e42dd4055cb4..58b3a96dbdcb 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -168,9 +168,6 @@ static int nftnl_gen_cmd_snprintf(char *buf, size_t size,
 {
 	int ret, remain = size, offset = 0;
 
-	if (size)
-		buf[0] = '\0';
-
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
 	SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
diff --git a/src/object.c b/src/object.c
index f907dd22d13a..9a4ee712a2a9 100644
--- a/src/object.c
+++ b/src/object.c
@@ -448,9 +448,6 @@ static int nftnl_obj_cmd_snprintf(char *buf, size_t size,
 {
 	int ret, remain = size, offset = 0;
 
-	if (size)
-		buf[0] = '\0';
-
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
 	SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
diff --git a/src/rule.c b/src/rule.c
index 7cbd15bbd93c..a9e9870cbea9 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -792,9 +792,6 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t size,
 	int ret, remain = size, offset = 0;
 	uint32_t inner_flags = flags;
 
-	if (size)
-		buf[0] = '\0';
-
 	inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
diff --git a/src/ruleset.c b/src/ruleset.c
index cc43866c13bc..3de9b8728329 100644
--- a/src/ruleset.c
+++ b/src/ruleset.c
@@ -846,9 +846,6 @@ nftnl_ruleset_do_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs
 	void *prev = NULL;
 	uint32_t inner_flags = flags;
 
-	if (size)
-		buf[0] = '\0';
-
 	/* dont pass events flags to child calls of _snprintf() */
 	inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
@@ -922,9 +919,6 @@ static int nftnl_ruleset_cmd_snprintf(char *buf, size_t size,
 				    const struct nftnl_ruleset *r, uint32_t cmd,
 				    uint32_t type, uint32_t flags)
 {
-	if (size)
-		buf[0] = '\0';
-
 	switch (type) {
 	case NFTNL_OUTPUT_DEFAULT:
 	case NFTNL_OUTPUT_JSON:
diff --git a/src/set.c b/src/set.c
index 36e59c38536c..592ea246b05e 100644
--- a/src/set.c
+++ b/src/set.c
@@ -895,9 +895,6 @@ static int nftnl_set_cmd_snprintf(char *buf, size_t size,
 	if (type == NFTNL_OUTPUT_XML)
 		return 0;
 
-	if (size)
-		buf[0] = '\0';
-
 	/* prevent set_elems to print as events */
 	inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
diff --git a/src/set_elem.c b/src/set_elem.c
index a99876a90cac..e45dbc6bfe3e 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -696,8 +696,6 @@ static int nftnl_set_elem_cmd_snprintf(char *buf, size_t size,
 
 	if (type == NFTNL_OUTPUT_XML)
 		return 0;
-	if (size)
-		buf[0] = '\0';
 
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
 	SNPRINTF_BUFFER_SIZE(ret, remain, offset);
diff --git a/src/table.c b/src/table.c
index db870cd98437..cf61ddaad3a6 100644
--- a/src/table.c
+++ b/src/table.c
@@ -378,9 +378,6 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t size,
 {
 	int ret, remain = size, offset = 0;
 
-	if (size)
-		buf[0] = '\0';
-
 	ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
 	SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
-- 
2.1.4


      parent reply	other threads:[~2017-10-04 12:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-04 12:23 [PATCH libnftnl,v2 1/4] buffer: use nftnl_expr_snprintf() from nftnl_buf_expr() Pablo Neira Ayuso
2017-10-04 12:23 ` [PATCH libnftnl,v2 2/4] expr: no need to nul-terminate buffer from expression ->snprintf indirection Pablo Neira Ayuso
2017-10-04 12:23 ` [PATCH libnftnl,v2 3/4] src: no need to nul-terminate buffer for nftnl_fprintf() calls Pablo Neira Ayuso
2017-10-04 12:23 ` Pablo Neira Ayuso [this message]

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=1507119803-15127-4-git-send-email-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.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).