tree data BUGFIX handle opaque nodes
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index b98ce77..196ab7d 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -275,6 +275,7 @@
 {
     int cmp;
     struct lyd_node *first;
+    const struct lys_module *own_mod;
 
     assert(node && mod);
 
@@ -283,7 +284,8 @@
     }
 
     first = *node;
-    cmp = strcmp(lyd_owner_module(first)->name, mod->name);
+    own_mod = lyd_owner_module(first);
+    cmp = own_mod ? strcmp(own_mod->name, mod->name) : 1;
     if (cmp > 0) {
         /* there may be some preceding data */
         while (first->prev->next) {