Subject: Re: [PATCH iproute2-next v2] f_flower: add cfm support

From: Stephen Hemminger <[email-masked]>
Date: Sun, 25 Jun 2023 12:03:41 -0700

On Tue, 20 Jun 2023 22:10:36 +0200
Zahari Doychev <[email-masked]> wrote:

> +	print_nl();
> +	print_string(PRINT_FP, NULL, "  cfm", NULL);
> +	open_json_object("cfm");
> +
> +	v = tb[TCA_FLOWER_KEY_CFM_MD_LEVEL];
> +	if (v) {
> +		sz += sprintf(out, " mdl %u", rta_getattr_u8(v));
> +		print_hhu(PRINT_JSON, "mdl", NULL, rta_getattr_u8(v));
> +
> +	}
> +
> +	v = tb[TCA_FLOWER_KEY_CFM_OPCODE];
> +	if (v) {
> +		sprintf(out + sz, " op %u", rta_getattr_u8(v));
> +		print_hhu(PRINT_JSON, "op", NULL, rta_getattr_u8(v));
> +
> +	}
> +
> +	close_json_object();
> +	print_string(PRINT_FP, "cfm", "%s", out);

Don't think you need to format the temporary string if you do this the easy way.
Just use print_uint?
	if (tb[TCA_FLOWER_KEY_CFM_MD_LEVEL])
		print_uint(PRINT_ANY, "mdl", " mdl %u",
			rta_getattr_u8(tb[TCA_FLOWER_KEY_CFM_MD_LEVEL]);

Since argument to print_uint is unsigned, the u8 will naturally get expanded.