@@ -783,10 +783,7 @@ 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;
if (!attr)
return;
@@ -794,27 +791,14 @@ static void print_masked_type(__u32 type_max,
value = rta_getattr_type(attr);
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));
- 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);
- }
- } 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_string(PRINT_FP, NULL, "%s ", _SL_);
+ print_uint_name_value(name, value);
+
+ if (mask != type_max) {
+ char mask_name[SPRINT_BSIZE-6];
+
+ snprintf(mask_name, sizeof(mask_name), "%s_mask", name);
+ print_hex(PRINT_ANY, mask_name, "/0x%x", mask);
}
}
Clang complains about passing a non-format string but the code here was doing extra work the JSON case. Using print_uint_name_value here makes the code much simpler. Old code was also broken if using 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> --- tc/tc_util.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)