lyb printer BUGFIX invalid memory access
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index bbec259..1d93bbb 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -404,6 +404,7 @@
 {
     if (!str) {
         str = "";
+        LY_CHECK_ERR_RET(str_len, LOGINT(lybctx->ctx), LY_EINT);
     }
     if (!str_len) {
         str_len = strlen(str);
@@ -992,7 +993,7 @@
     struct hash_table *top_sibling_ht = NULL;
     const struct lys_module *prev_mod = NULL;
     struct lyd_lyb_ctx *lybctx;
-    const struct ly_ctx *ctx = LYD_NODE_CTX(root);
+    const struct ly_ctx *ctx = root ? LYD_NODE_CTX(root) : NULL;
 
     lybctx = calloc(1, sizeof *lybctx);
     LY_CHECK_ERR_RET(!lybctx, LOGMEM(ctx), LY_EMEM);