From: Stephen Hemminger <stephen@networkplumber.org>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>, elibr@mellanox.com
Subject: [PATCH v4 iproute2-next 05/11] tc_util: fix clang warning in print_masked_type
Date: Thu, 20 Jan 2022 13:11:47 -0800 [thread overview]
Message-ID: <20220120211153.189476-6-stephen@networkplumber.org> (raw)
In-Reply-To: <20220120211153.189476-1-stephen@networkplumber.org>
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 | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
diff --git a/tc/tc_util.c b/tc/tc_util.c
index 6d5eb754831a..78cb9901f7b9 100644
--- a/tc/tc_util.c
+++ b/tc/tc_util.c
@@ -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,18 @@ 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);
+ if (newline)
+ print_string(PRINT_FP, NULL, "%s ", _SL_);
+ else
+ print_string(PRINT_FP, NULL, " ", _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);
}
}
--
2.30.2
next prev parent reply other threads:[~2022-01-20 21:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-20 21:11 [PATCH v4 iproute2-next 00/11] fix clang warnings Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 01/11] tc: add format attribute to tc_print_rate Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 02/11] utils: add format attribute Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 03/11] netem: fix clang warnings Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 04/11] flower: " Stephen Hemminger
2022-01-20 21:11 ` Stephen Hemminger [this message]
2022-01-20 21:11 ` [PATCH v4 iproute2-next 06/11] ipl2tp: fix clang warning Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 07/11] can: " Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 08/11] tipc: fix clang warning about empty format string Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 09/11] tunnel: fix clang warning Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 10/11] libbpf: fix clang warning about format non-literal Stephen Hemminger
2022-01-20 21:11 ` [PATCH v4 iproute2-next 11/11] json_print: suppress clang format warning Stephen Hemminger
2022-01-26 17:30 ` [PATCH v4 iproute2-next 00/11] fix clang warnings patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220120211153.189476-6-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=elibr@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).