]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
expr: data_reg: Avoid extra whitespace
authorPhil Sutter <phil@nwl.cc>
Wed, 15 Oct 2025 21:41:36 +0000 (23:41 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 27 Jan 2026 21:59:15 +0000 (22:59 +0100)
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>
src/expr/bitwise.c
src/expr/cmp.c
src/expr/data_reg.c
src/expr/immediate.c
src/expr/range.c
src/set_elem.c

index cac47a5500993079d0ab0a662a875cbe3e9b4661..2da83b7ba0441593eb6396dadfb5e382a49d5b4f 100644 (file)
@@ -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;
index 2908f56325b45a96cda781c17028ceaf5aa88fb2..ec1dc318947712536faa58ff648ef58562941a66 100644 (file)
@@ -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;
 }
 
index fd5e0d6e749e17a37dfca81c9b504e94f79b8c0f..bf4153c072fd0580c7d48da8745ae9640137bb69 100644 (file)
@@ -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);
        }
 
index f0e0a78d6b794eee53bddc351acac5c0f49ecd98..6dffaf9ce4ad930dc0968bdff4a61f25758ce503 100644 (file)
@@ -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;
 }
 
index 50a8ed092e38fe60bd58b39cacf60aaa49e120e4..564d14f0edbbb93a46081e20cc870469232f1c05 100644 (file)
@@ -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;
 }
 
index 6c1be44ce507331f5884814ef16b430a5e6ecc6d..f567a28719d11067c909522d0ee02ff6ebfb47ef 100644 (file)
@@ -720,12 +720,12 @@ int nftnl_set_elem_snprintf_default(char *buf, size_t remain,
                                              DATA_F_NOPFX, dregtype);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        } else if (e->flags & (1 << NFTNL_SET_ELEM_OBJREF)) {
-               ret = snprintf(buf + offset, remain, " : %s ", e->objref);
+               ret = snprintf(buf + offset, remain, " : %s", e->objref);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (e->set_elem_flags) {
-               ret = snprintf(buf + offset, remain, "flags %u ", e->set_elem_flags);
+               ret = snprintf(buf + offset, remain, " flags %u", e->set_elem_flags);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }