]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
rule: Don't append a newline when printing a rule
authorPhil Sutter <phil@nwl.cc>
Tue, 1 Oct 2024 16:01:43 +0000 (18:01 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 1 Oct 2024 19:44:24 +0000 (21:44 +0200)
Since commit c759027a526ac, printed rules may or may not end with a
newline depending on whether userdata was present or not. Deal with this
inconsistency by avoiding the trailing newline in all cases.

Fixes: c759027a526ac ("rule, set_elem: remove trailing \n in userdata snprintf")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/rule.c

index 811d5a213f83587ddf56bbd048aefbb8faf6e22f..c22918a8f35271228aed856665c8689fb3737616 100644 (file)
@@ -573,23 +573,21 @@ static int nftnl_rule_snprintf_default(char *buf, size_t remain,
                sep = " ";
        }
 
-       ret = snprintf(buf + offset, remain, "\n");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        list_for_each_entry(expr, &r->expr_list, head) {
-               ret = snprintf(buf + offset, remain, "  [ %s ", expr->ops->name);
+               ret = snprintf(buf + offset, remain,
+                              "\n  [ %s ", expr->ops->name);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
                ret = nftnl_expr_snprintf(buf + offset, remain, expr,
                                             type, flags);
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
-               ret = snprintf(buf + offset, remain, "]\n");
+               ret = snprintf(buf + offset, remain, "]");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
        if (r->user.len) {
-               ret = snprintf(buf + offset, remain, "  userdata = { ");
+               ret = snprintf(buf + offset, remain, "\n  userdata = { ");
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
                for (i = 0; i < r->user.len; i++) {