diff mbox series

[iproute2-next,05/11] flower: fix clang warnings

Message ID 20220108204650.36185-6-sthemmin@microsoft.com (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series Clang warning fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Jan. 8, 2022, 8:46 p.m. UTC
Clang complains about passing non-format string to print_string.
Handle this by splitting json and non-json parts.

Signed-off-by: Stephen Hemminger <sthemmin@microsoft.com>
---
 tc/f_flower.c | 62 ++++++++++++++++++++++++---------------------------
 1 file changed, 29 insertions(+), 33 deletions(-)

Comments

David Ahern Jan. 11, 2022, 4 p.m. UTC | #1
On 1/8/22 1:46 PM, Stephen Hemminger wrote:
> @@ -1925,10 +1925,17 @@ static int __mask_bits(char *addr, size_t len)
>  	return bits;
>  }
>  
> -static void flower_print_eth_addr(char *name, struct rtattr *addr_attr,
> +static void flower_print_string(const char *name, const char *value)
> +{
> +	print_nl();
> +	print_string(PRINT_JSON, name, NULL, value);
> +	print_string(PRINT_FP, NULL, "  %s", name);
> +	print_string(PRINT_FP, NULL, " %s", value);
> +}
> +

The last 3 lines could be a generic print_string_name_value function
under lib.


> @@ -2237,16 +2235,20 @@ static void flower_print_ct_mark(struct rtattr *attr,
>  	print_masked_u32("ct_mark", attr, mask_attr, true);
>  }
>  
> -static void flower_print_key_id(const char *name, struct rtattr *attr)
> +static void flower_print_uint(const char *name, unsigned int val)
>  {
> -	SPRINT_BUF(namefrm);
> +	print_nl();
> +	print_uint(PRINT_JSON, name, NULL, val);
> +	print_string(PRINT_FP, NULL, "  %s", name);
> +	print_uint(PRINT_FP, NULL, " %%u", val);

s/%%u/%u/ ?

Same here the last 3 lines could be a lib function.
diff mbox series

Patch

diff --git a/tc/f_flower.c b/tc/f_flower.c
index 7f78195fd303..d6ff94ddbefb 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -1925,10 +1925,17 @@  static int __mask_bits(char *addr, size_t len)
 	return bits;
 }
 
-static void flower_print_eth_addr(char *name, struct rtattr *addr_attr,
+static void flower_print_string(const char *name, const char *value)
+{
+	print_nl();
+	print_string(PRINT_JSON, name, NULL, value);
+	print_string(PRINT_FP, NULL, "  %s", name);
+	print_string(PRINT_FP, NULL, " %s", value);
+}
+
+static void flower_print_eth_addr(const char *name, struct rtattr *addr_attr,
 				  struct rtattr *mask_attr)
 {
-	SPRINT_BUF(namefrm);
 	SPRINT_BUF(out);
 	SPRINT_BUF(b1);
 	size_t done;
@@ -1949,9 +1956,7 @@  static void flower_print_eth_addr(char *name, struct rtattr *addr_attr,
 			sprintf(out + done, "/%d", bits);
 	}
 
-	print_nl();
-	sprintf(namefrm, "  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
+	flower_print_string(name, out);
 }
 
 static void flower_print_eth_type(__be16 *p_eth_type,
@@ -2064,7 +2069,6 @@  static void flower_print_ip_addr(char *name, __be16 eth_type,
 {
 	struct rtattr *addr_attr;
 	struct rtattr *mask_attr;
-	SPRINT_BUF(namefrm);
 	SPRINT_BUF(out);
 	size_t done;
 	int family;
@@ -2095,10 +2099,9 @@  static void flower_print_ip_addr(char *name, __be16 eth_type,
 	else if (bits < len * 8)
 		sprintf(out + done, "/%d", bits);
 
-	print_nl();
-	sprintf(namefrm, "  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
+	flower_print_string(name, out);
 }
+
 static void flower_print_ip4_addr(char *name, struct rtattr *addr_attr,
 				  struct rtattr *mask_attr)
 {
@@ -2124,22 +2127,19 @@  static void flower_print_port_range(char *name, struct rtattr *min_attr,
 		print_hu(PRINT_JSON, "end", NULL, rta_getattr_be16(max_attr));
 		close_json_object();
 	} else {
-		SPRINT_BUF(namefrm);
 		SPRINT_BUF(out);
 		size_t done;
 
 		done = sprintf(out, "%u", rta_getattr_be16(min_attr));
 		sprintf(out + done, "-%u", rta_getattr_be16(max_attr));
-		print_nl();
-		sprintf(namefrm, "  %s %%s", name);
-		print_string(PRINT_ANY, name, namefrm, out);
+
+		flower_print_string(name, out);
 	}
 }
 
 static void flower_print_tcp_flags(const char *name, struct rtattr *flags_attr,
 				   struct rtattr *mask_attr)
 {
-	SPRINT_BUF(namefrm);
 	SPRINT_BUF(out);
 	size_t done;
 
@@ -2150,9 +2150,7 @@  static void flower_print_tcp_flags(const char *name, struct rtattr *flags_attr,
 	if (mask_attr)
 		sprintf(out + done, "/%x", rta_getattr_be16(mask_attr));
 
-	print_nl();
-	sprintf(namefrm, "  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
+	flower_print_string(name, out);
 }
 
 static void flower_print_ct_state(struct rtattr *flags_attr,
@@ -2237,16 +2235,20 @@  static void flower_print_ct_mark(struct rtattr *attr,
 	print_masked_u32("ct_mark", attr, mask_attr, true);
 }
 
-static void flower_print_key_id(const char *name, struct rtattr *attr)
+static void flower_print_uint(const char *name, unsigned int val)
 {
-	SPRINT_BUF(namefrm);
+	print_nl();
+	print_uint(PRINT_JSON, name, NULL, val);
+	print_string(PRINT_FP, NULL, "  %s", name);
+	print_uint(PRINT_FP, NULL, " %%u", val);
+}
 
+static void flower_print_key_id(const char *name, struct rtattr *attr)
+{
 	if (!attr)
 		return;
 
-	print_nl();
-	sprintf(namefrm, "  %s %%u", name);
-	print_uint(PRINT_ANY, name, namefrm, rta_getattr_be32(attr));
+	flower_print_uint(name, rta_getattr_be32(attr));
 }
 
 static void flower_print_geneve_opts(const char *name, struct rtattr *attr,
@@ -2342,8 +2344,9 @@  static void flower_print_erspan_opts(const char *name, struct rtattr *attr,
 	sprintf(strbuf, "%u:%u:%u:%u", ver, idx, dir, hwid);
 }
 
-static void flower_print_enc_parts(const char *name, const char *namefrm,
-				   struct rtattr *attr, char *key, char *mask)
+static void __attribute__((format(printf, 2, 0)))
+flower_print_enc_parts(const char *name, const char *namefrm,
+		       struct rtattr *attr, char *key, char *mask)
 {
 	char *key_token, *mask_token, *out;
 	int len;
@@ -2431,7 +2434,6 @@  static void flower_print_masked_u8(const char *name, struct rtattr *attr,
 {
 	const char *value_str = NULL;
 	__u8 value, mask;
-	SPRINT_BUF(namefrm);
 	SPRINT_BUF(out);
 	size_t done;
 
@@ -2451,9 +2453,7 @@  static void flower_print_masked_u8(const char *name, struct rtattr *attr,
 	if (mask != UINT8_MAX)
 		sprintf(out + done, "/%d", mask);
 
-	print_nl();
-	sprintf(namefrm, "  %s %%s", name);
-	print_string(PRINT_ANY, name, namefrm, out);
+	flower_print_string(name, out);
 }
 
 static void flower_print_u8(const char *name, struct rtattr *attr)
@@ -2463,14 +2463,10 @@  static void flower_print_u8(const char *name, struct rtattr *attr)
 
 static void flower_print_u32(const char *name, struct rtattr *attr)
 {
-	SPRINT_BUF(namefrm);
-
 	if (!attr)
 		return;
 
-	print_nl();
-	sprintf(namefrm, "  %s %%u", name);
-	print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr));
+	flower_print_uint(name, rta_getattr_u32(attr));
 }
 
 static void flower_print_mpls_opt_lse(struct rtattr *lse)