]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc_util: fix clang warning in print_masked_type
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 11 Jan 2022 17:54:32 +0000 (09:54 -0800)
committerDavid Ahern <dsahern@kernel.org>
Wed, 26 Jan 2022 17:19:08 +0000 (10:19 -0700)
Clang complains about passing a non-format string but the code here.
The old code was doing extra work the JSON case. JSON ignores one line mode.
This also fixes output format in oneline mode.

Fixes: 04b215015ba8 ("tc_util: introduce a function to print JSON/non-JSON masked numbers")
Cc: elibr@mellanox.com
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@kernel.org>
tc/tc_util.c

index 6d5eb754831aab013a286cc56e3a177671d451b3..67960d2c03d781075fd61b7cfcac1d26c849844c 100644 (file)
@@ -783,7 +783,6 @@ static void print_masked_type(__u32 type_max,
                              const char *name, struct rtattr *attr,
                              struct rtattr *mask_attr, bool newline)
 {
-       SPRINT_BUF(namefrm);
        __u32 value, mask;
        SPRINT_BUF(out);
        size_t done;
@@ -795,26 +794,20 @@ static void print_masked_type(__u32 type_max,
        mask = mask_attr ? rta_getattr_type(mask_attr) : type_max;
 
        if (is_json_context()) {
-               sprintf(namefrm, "\n  %s %%u", name);
-               print_hu(PRINT_ANY, name, namefrm,
-                        rta_getattr_type(attr));
+               print_hu(PRINT_JSON, name, NULL, value);
                if (mask != type_max) {
                        char mask_name[SPRINT_BSIZE-6];
 
                        sprintf(mask_name, "%s_mask", name);
-                       if (newline)
-                               print_string(PRINT_FP, NULL, "%s ", _SL_);
-                       sprintf(namefrm, " %s %%u", mask_name);
-                       print_hu(PRINT_ANY, mask_name, namefrm, mask);
+                       print_hu(PRINT_JSON, mask_name, NULL, mask);
                }
        } else {
                done = sprintf(out, "%u", value);
                if (mask != type_max)
                        sprintf(out + done, "/0x%x", mask);
-               if (newline)
-                       print_string(PRINT_FP, NULL, "%s ", _SL_);
-               sprintf(namefrm, " %s %%s", name);
-               print_string(PRINT_ANY, name, namefrm, out);
+
+               print_nl();
+               print_string_name_value(name, out);
        }
 }