* [PATCH libnftnl,v2 2/4] expr: no need to nul-terminate buffer from expression ->snprintf indirection
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 ` 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 ` [PATCH libnftnl,v2 4/4] src: do not nul-terminate internal helper functions Pablo Neira Ayuso
2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:23 UTC (permalink / raw)
To: netfilter-devel
->snprintf() is always called via nftnl_expr_snprintf() wrapper, which
is already dealing with this corner case for us.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/expr/bitwise.c | 3 ---
src/expr/byteorder.c | 3 ---
src/expr/cmp.c | 3 ---
src/expr/counter.c | 3 ---
src/expr/ct.c | 3 ---
src/expr/dup.c | 3 ---
src/expr/dynset.c | 3 ---
src/expr/exthdr.c | 3 ---
src/expr/fib.c | 3 ---
src/expr/fwd.c | 3 ---
src/expr/hash.c | 3 ---
src/expr/immediate.c | 3 ---
src/expr/limit.c | 3 ---
src/expr/log.c | 3 ---
src/expr/lookup.c | 3 ---
src/expr/masq.c | 3 ---
src/expr/match.c | 3 ---
src/expr/meta.c | 3 ---
src/expr/nat.c | 3 ---
src/expr/numgen.c | 3 ---
src/expr/objref.c | 3 ---
src/expr/payload.c | 3 ---
src/expr/queue.c | 3 ---
src/expr/quota.c | 3 ---
src/expr/range.c | 3 ---
src/expr/redir.c | 3 ---
src/expr/reject.c | 3 ---
src/expr/rt.c | 3 ---
src/expr/target.c | 3 ---
29 files changed, 87 deletions(-)
diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
index ff9ade4d86d0..a89734b5f2d4 100644
--- a/src/expr/bitwise.c
+++ b/src/expr/bitwise.c
@@ -257,9 +257,6 @@ static int
nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_bitwise_snprintf_default(buf, size, e);
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index 4bb95b497701..47c04cfea69f 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -272,9 +272,6 @@ static int
nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_byteorder_snprintf_default(buf, size, e);
diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index 7bafaec573e7..b26d0eb08bb2 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -246,9 +246,6 @@ static int
nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_cmp_snprintf_default(buf, size, e);
diff --git a/src/expr/counter.c b/src/expr/counter.c
index 5c196d451843..21901e892471 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.c
@@ -164,9 +164,6 @@ static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags,
const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_counter_snprintf_default(buf, len, e);
diff --git a/src/expr/ct.c b/src/expr/ct.c
index 021a27795a69..6f87a72487ae 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -317,9 +317,6 @@ static int
nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_ct_snprintf_default(buf, len, e);
diff --git a/src/expr/dup.c b/src/expr/dup.c
index e2171f4ef1fb..ed8e6208cfab 100644
--- a/src/expr/dup.c
+++ b/src/expr/dup.c
@@ -170,9 +170,6 @@ static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/dynset.c b/src/expr/dynset.c
index 2755d492e085..160d0e15c151 100644
--- a/src/expr/dynset.c
+++ b/src/expr/dynset.c
@@ -314,9 +314,6 @@ static int
nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_dynset_snprintf_default(buf, size, e);
diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index 11766fafc027..75cafbc113f7 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -339,9 +339,6 @@ static int
nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_exthdr_snprintf_default(buf, len, e);
diff --git a/src/expr/fib.c b/src/expr/fib.c
index cbadeef7ce49..b922b26681e7 100644
--- a/src/expr/fib.c
+++ b/src/expr/fib.c
@@ -236,9 +236,6 @@ static int
nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_fib_snprintf_default(buf, len, e);
diff --git a/src/expr/fwd.c b/src/expr/fwd.c
index 38923df64760..1312ea10b07c 100644
--- a/src/expr/fwd.c
+++ b/src/expr/fwd.c
@@ -147,9 +147,6 @@ static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/hash.c b/src/expr/hash.c
index 066c790d5b50..fcc4fa5c0516 100644
--- a/src/expr/hash.c
+++ b/src/expr/hash.c
@@ -288,9 +288,6 @@ static int
nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_hash_snprintf_default(buf, len, e);
diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index aba84ea0823e..b0570bd539a4 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -262,9 +262,6 @@ static int
nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
diff --git a/src/expr/limit.c b/src/expr/limit.c
index 8e1f02abb617..856ab1839b0a 100644
--- a/src/expr/limit.c
+++ b/src/expr/limit.c
@@ -243,9 +243,6 @@ static int
nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_limit_snprintf_default(buf, len, e);
diff --git a/src/expr/log.c b/src/expr/log.c
index 161327b4b5f2..86d965136cd4 100644
--- a/src/expr/log.c
+++ b/src/expr/log.c
@@ -301,9 +301,6 @@ static int
nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_log_snprintf_default(buf, len, e);
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 32220a30dbce..5fcb81f3a7a2 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -242,9 +242,6 @@ static int
nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch(type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_lookup_snprintf_default(buf, size, e);
diff --git a/src/expr/masq.c b/src/expr/masq.c
index 1c75ee9cdd53..7c235d3b0bdc 100644
--- a/src/expr/masq.c
+++ b/src/expr/masq.c
@@ -190,9 +190,6 @@ static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_masq_snprintf_default(buf, len, e);
diff --git a/src/expr/match.c b/src/expr/match.c
index af659b3821c8..dd09e1e85192 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -200,9 +200,6 @@ nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
{
struct nftnl_expr_match *match = nftnl_expr_data(e);
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return snprintf(buf, len, "name %s rev %u ",
diff --git a/src/expr/meta.c b/src/expr/meta.c
index b5c27e66dc51..2c758412bf2e 100644
--- a/src/expr/meta.c
+++ b/src/expr/meta.c
@@ -252,9 +252,6 @@ static int
nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_meta_snprintf_default(buf, len, e);
diff --git a/src/expr/nat.c b/src/expr/nat.c
index 350633fd5e0a..92713033a6e7 100644
--- a/src/expr/nat.c
+++ b/src/expr/nat.c
@@ -339,9 +339,6 @@ static int
nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_nat_snprintf_default(buf, size, e);
diff --git a/src/expr/numgen.c b/src/expr/numgen.c
index 9b5b1b789206..1369b01d9401 100644
--- a/src/expr/numgen.c
+++ b/src/expr/numgen.c
@@ -224,9 +224,6 @@ static int
nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_ng_snprintf_default(buf, len, e);
diff --git a/src/expr/objref.c b/src/expr/objref.c
index b4b3383e8a7c..4cfa3cbfbd2b 100644
--- a/src/expr/objref.c
+++ b/src/expr/objref.c
@@ -236,9 +236,6 @@ static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags,
const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_objref_snprintf_default(buf, len, e);
diff --git a/src/expr/payload.c b/src/expr/payload.c
index 897fc7746166..91e1587ff239 100644
--- a/src/expr/payload.c
+++ b/src/expr/payload.c
@@ -290,9 +290,6 @@ nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
{
struct nftnl_expr_payload *payload = nftnl_expr_data(e);
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
if (payload->sreg)
diff --git a/src/expr/queue.c b/src/expr/queue.c
index e0fb785a490b..a392a271a6fb 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -235,9 +235,6 @@ static int
nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_queue_snprintf_default(buf, len, e);
diff --git a/src/expr/quota.c b/src/expr/quota.c
index c247b0a03341..667e6e17c28c 100644
--- a/src/expr/quota.c
+++ b/src/expr/quota.c
@@ -183,9 +183,6 @@ static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags,
const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_quota_snprintf_default(buf, len, e);
diff --git a/src/expr/range.c b/src/expr/range.c
index c7bb7c7f3d7a..b2789ffaada3 100644
--- a/src/expr/range.c
+++ b/src/expr/range.c
@@ -263,9 +263,6 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (size)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_range_snprintf_default(buf, size, e);
diff --git a/src/expr/redir.c b/src/expr/redir.c
index 9fb634afaa19..b2aa3453870a 100644
--- a/src/expr/redir.c
+++ b/src/expr/redir.c
@@ -204,9 +204,6 @@ static int
nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_redir_snprintf_default(buf, len, e);
diff --git a/src/expr/reject.c b/src/expr/reject.c
index 1e6fdf5c5ba0..11d8b20096ae 100644
--- a/src/expr/reject.c
+++ b/src/expr/reject.c
@@ -164,9 +164,6 @@ static int
nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_reject_snprintf_default(buf, len, e);
diff --git a/src/expr/rt.c b/src/expr/rt.c
index 10cb1e27ce68..62c01a0be0f5 100644
--- a/src/expr/rt.c
+++ b/src/expr/rt.c
@@ -203,9 +203,6 @@ static int
nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, const struct nftnl_expr *e)
{
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return nftnl_expr_rt_snprintf_default(buf, len, e);
diff --git a/src/expr/target.c b/src/expr/target.c
index 3c58b03d20dd..ed4bf7df6328 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -200,9 +200,6 @@ nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
{
struct nftnl_expr_target *target = nftnl_expr_data(e);
- if (len)
- buf[0] = '\0';
-
switch (type) {
case NFTNL_OUTPUT_DEFAULT:
return snprintf(buf, len, "name %s rev %u ",
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH libnftnl,v2 3/4] src: no need to nul-terminate buffer for nftnl_fprintf() calls
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 ` Pablo Neira Ayuso
2017-10-04 12:23 ` [PATCH libnftnl,v2 4/4] src: do not nul-terminate internal helper functions Pablo Neira Ayuso
2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:23 UTC (permalink / raw)
To: netfilter-devel
This function bails out with -1 if we cannot print, and this buffer is
internally allocated. No need for this overly deffensive initialization.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/chain.c | 3 ---
src/common.c | 6 ------
src/gen.c | 3 ---
src/object.c | 3 ---
src/rule.c | 3 ---
src/set.c | 3 ---
src/set_elem.c | 3 ---
src/table.c | 3 ---
8 files changed, 27 deletions(-)
diff --git a/src/chain.c b/src/chain.c
index 6df871df4131..5e30a8016cac 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -867,9 +867,6 @@ EXPORT_SYMBOL(nftnl_chain_snprintf);
static int nftnl_chain_do_snprintf(char *buf, size_t size, const void *c,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_chain_snprintf(buf, size, c, type, flags);
}
diff --git a/src/common.c b/src/common.c
index ba5a49fc8470..a95883c19080 100644
--- a/src/common.c
+++ b/src/common.c
@@ -94,9 +94,6 @@ EXPORT_SYMBOL(nftnl_parse_perror);
int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
NFTNL_BUF_INIT(b, buf, size);
if (cmd == NFTNL_CMD_UNSPEC)
@@ -138,9 +135,6 @@ int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t type,
int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
NFTNL_BUF_INIT(b, buf, size);
if (cmd == NFTNL_CMD_UNSPEC)
diff --git a/src/gen.c b/src/gen.c
index a03648bba1c2..e42dd4055cb4 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -203,9 +203,6 @@ EXPORT_SYMBOL(nftnl_gen_snprintf);
static int nftnl_gen_do_snprintf(char *buf, size_t size, const void *gen,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf = '\0';
-
return nftnl_gen_snprintf(buf, size, gen, type, flags);
}
diff --git a/src/object.c b/src/object.c
index 8dc83b36c32e..f907dd22d13a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -488,9 +488,6 @@ EXPORT_SYMBOL(nftnl_obj_snprintf);
static int nftnl_obj_do_snprintf(char *buf, size_t size, const void *obj,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_obj_snprintf(buf, size, obj, type, flags);
}
diff --git a/src/rule.c b/src/rule.c
index f37806c0e07b..7cbd15bbd93c 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -836,9 +836,6 @@ EXPORT_SYMBOL(nftnl_rule_snprintf);
static int nftnl_rule_do_snprintf(char *buf, size_t size, const void *r,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_rule_snprintf(buf, size, r, type, flags);
}
diff --git a/src/set.c b/src/set.c
index a4e41d2a3547..36e59c38536c 100644
--- a/src/set.c
+++ b/src/set.c
@@ -939,9 +939,6 @@ EXPORT_SYMBOL(nftnl_set_snprintf);
static int nftnl_set_do_snprintf(char *buf, size_t size, const void *s,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_set_snprintf(buf, size, s, type, flags);
}
diff --git a/src/set_elem.c b/src/set_elem.c
index a8f88a4f1813..a99876a90cac 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -738,9 +738,6 @@ static int nftnl_set_elem_do_snprintf(char *buf, size_t size, const void *e,
uint32_t cmd, uint32_t type,
uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_set_elem_snprintf(buf, size, e, type, flags);
}
diff --git a/src/table.c b/src/table.c
index 4d8176c9be78..db870cd98437 100644
--- a/src/table.c
+++ b/src/table.c
@@ -417,9 +417,6 @@ EXPORT_SYMBOL(nftnl_table_snprintf);
static int nftnl_table_do_snprintf(char *buf, size_t size, const void *t,
uint32_t cmd, uint32_t type, uint32_t flags)
{
- if (size)
- buf[0] = '\0';
-
return nftnl_table_snprintf(buf, size, t, type, flags);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH libnftnl,v2 4/4] src: do not nul-terminate internal helper functions
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
2 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2017-10-04 12:23 UTC (permalink / raw)
To: netfilter-devel
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
^ permalink raw reply related [flat|nested] 4+ messages in thread