From 7daf5a4fde637dfc2aee4480c48777b6e5b22aa2 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Wed, 15 Oct 2025 23:41:36 +0200 Subject: 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 --- src/expr/data_reg.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/expr/data_reg.c') 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); } -- cgit v1.2.3