summaryrefslogtreecommitdiffstats
path: root/src/expr
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2025-10-15 23:41:36 +0200
committerPhil Sutter <phil@nwl.cc>2026-01-27 22:59:15 +0100
commit7daf5a4fde637dfc2aee4480c48777b6e5b22aa2 (patch)
tree40621581fad41e6f6ad09daee5b35afc48af4fcc /src/expr
parent5f72061e6e34328ad40e0f1ffd2b8188356bd5f9 (diff)
expr: data_reg: Avoid extra whitespace
Do not append a space to data regs, they may appear at end of line or followed by a tab. Have callers print the space if needed. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'src/expr')
-rw-r--r--src/expr/bitwise.c7
-rw-r--r--src/expr/cmp.c3
-rw-r--r--src/expr/data_reg.c11
-rw-r--r--src/expr/immediate.c3
-rw-r--r--src/expr/range.c6
5 files changed, 22 insertions, 8 deletions
diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
index cac47a5..2da83b7 100644
--- a/src/expr/bitwise.c
+++ b/src/expr/bitwise.c
@@ -225,13 +225,16 @@ nftnl_expr_bitwise_snprintf_mask_xor(char *buf, size_t remain,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- ret = snprintf(buf + offset, remain, ") ^ ");
+ ret = snprintf(buf + offset, remain, " ) ^ ");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
ret = nftnl_data_reg_snprintf(buf + offset, remain, &bitwise->xor,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ ret = snprintf(buf + offset, remain, " ");
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
return offset;
}
@@ -248,7 +251,7 @@ nftnl_expr_bitwise_snprintf_shift(char *buf, size_t remain, const char *op,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
- ret = snprintf(buf + offset, remain, ") ");
+ ret = snprintf(buf + offset, remain, " ) ");
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
return offset;
diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index 2908f56..ec1dc31 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -163,6 +163,9 @@ nftnl_expr_cmp_snprintf(char *buf, size_t remain,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ ret = snprintf(buf + offset, remain, " ");
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
return offset;
}
diff --git a/src/expr/data_reg.c b/src/expr/data_reg.c
index fd5e0d6..bf4153c 100644
--- a/src/expr/data_reg.c
+++ b/src/expr/data_reg.c
@@ -25,15 +25,14 @@ nftnl_data_reg_value_snprintf_default(char *buf, size_t remain,
const union nftnl_data_reg *reg,
uint32_t flags)
{
- const char *pfx = flags & DATA_F_NOPFX ? "" : "0x";
+ const char *pfx = flags & DATA_F_NOPFX ? "" : "0x", *sep = "";
int offset = 0, ret, i;
-
-
for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
ret = snprintf(buf + offset, remain,
- "%s%.8x ", pfx, reg->val[i]);
+ "%s%s%.8x", sep, pfx, reg->val[i]);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ sep = " ";
}
return offset;
@@ -46,11 +45,11 @@ nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size,
{
int remain = size, offset = 0, ret = 0;
- ret = snprintf(buf, size, "%s ", nftnl_verdict2str(reg->verdict));
+ ret = snprintf(buf, size, "%s", nftnl_verdict2str(reg->verdict));
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
if (reg->chain != NULL) {
- ret = snprintf(buf + offset, remain, "-> %s ", reg->chain);
+ ret = snprintf(buf + offset, remain, " -> %s", reg->chain);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index f0e0a78..6dffaf9 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -201,6 +201,9 @@ nftnl_expr_immediate_snprintf(char *buf, size_t remain,
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
}
+ ret = snprintf(buf + offset, remain, " ");
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
return offset;
}
diff --git a/src/expr/range.c b/src/expr/range.c
index 50a8ed0..564d14f 100644
--- a/src/expr/range.c
+++ b/src/expr/range.c
@@ -176,10 +176,16 @@ static int nftnl_expr_range_snprintf(char *buf, size_t remain,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ ret = snprintf(buf + offset, remain, " ");
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
ret = nftnl_data_reg_snprintf(buf + offset, remain, &range->data_to,
0, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+ ret = snprintf(buf + offset, remain, " ");
+ SNPRINTF_BUFFER_SIZE(ret, remain, offset);
+
return offset;
}