data printers BUGFIX handling print of no data (NULL tree)
diff --git a/src/printer_data.c b/src/printer_data.c
index 1cdc0c2..05a0ef0 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -56,12 +56,14 @@
/* reset the number of printed bytes */
out->func_printed = 0;
- /* get first top-level sibling */
- while (root->parent) {
- root = (struct lyd_node *)root->parent;
- }
- while (root->prev->next) {
- root = root->prev;
+ if (root) {
+ /* get first top-level sibling */
+ while (root->parent) {
+ root = (struct lyd_node *)root->parent;
+ }
+ while (root->prev->next) {
+ root = root->prev;
+ }
}
/* print each top-level sibling */
diff --git a/src/printer_json.c b/src/printer_json.c
index d002da1..0f77615 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -858,6 +858,12 @@
struct jsonpr_ctx ctx = {0};
const char *delimiter = (options & LYD_PRINT_FORMAT) ? "\n" : "";
+ if (!root) {
+ ly_print_(out, "{}%s", delimiter);
+ ly_print_flush(out);
+ return LY_SUCCESS;
+ }
+
ctx.out = out;
ctx.level = 1;
ctx.level_printed = 0;