diff mbox series

[iproute2-next,18/20] json_print: Output to temporary buffer in print_range() only as needed

Message ID 20231211140732.11475-19-bpoirier@nvidia.com (mailing list archive)
State Accepted
Delegated to: Stephen Hemminger
Headers show
Series bridge: vni: UI fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Benjamin Poirier Dec. 11, 2023, 2:07 p.m. UTC
The string that's formatted in the "end" buffer is only needed when
outputting a range so move the snprintf() call within the condition.

Reviewed-by: Petr Machata <petrm@nvidia.com>
Tested-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com>
---
 lib/json_print.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/lib/json_print.c b/lib/json_print.c
index 072105c0..f38171ff 100644
--- a/lib/json_print.c
+++ b/lib/json_print.c
@@ -377,14 +377,15 @@  int print_color_rate(bool use_iec, enum output_type type, enum color_attr color,
 
 unsigned int print_range(const char *name, __u32 start, __u32 id)
 {
-	char end[64];
 	int width;
 
-	snprintf(end, sizeof(end), "%sEnd", name);
-
 	width = print_uint(PRINT_ANY, name, "%u", start);
-	if (start != id)
+	if (start != id) {
+		char end[64];
+
+		snprintf(end, sizeof(end), "%sEnd", name);
 		width += print_uint(PRINT_ANY, end, "-%u", id);
+	}
 
 	return width;
 }