summaryrefslogtreecommitdiff
path: root/lib/vty.c
diff options
context:
space:
mode:
authorChirag Shah <chirag@nvidia.com>2023-10-29 11:20:37 -0700
committerChirag Shah <chirag@nvidia.com>2023-10-29 11:20:37 -0700
commit43443e828a0b1147fc0866b3e13205d4e7903a65 (patch)
treee9edb671818cfa46541ac2bb228c9ed406ef9a92 /lib/vty.c
parent4d7f6295c6487b438d50280c1d7ddfe490d4749c (diff)
*: modify empty json helper function
Modify empty json object to take input obj instead of allocating always one. There are situation where in error condition or no data case print empty json (`{}`) with already allocated Signed-off-by: Chirag Shah <chirag@nvidia.com>
Diffstat (limited to 'lib/vty.c')
-rw-r--r--lib/vty.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/vty.c b/lib/vty.c
index d6a0dba206..c0d396ebdc 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -343,11 +343,14 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json)
return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE);
}
-void vty_json_empty(struct vty *vty)
+void vty_json_empty(struct vty *vty, struct json_object *json)
{
- json_object *json = json_object_new_object();
+ json_object *jsonobj = json;
- vty_json(vty, json);
+ if (!json)
+ jsonobj = json_object_new_object();
+
+ vty_json(vty, jsonobj);
}
/* Output current time to the vty. */