tree BUGFIX NULL pointer dereference
diff --git a/src/tree.c b/src/tree.c
index 10b33bf..a6c3889 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -1989,10 +1989,12 @@
     for (j = 0; j < module->inc_size; j++) {
         for (i = 0; i < module->inc[j].submodule->features_size; i++) {
             result[count] = module->inc[j].submodule->features[i].name;
-            if (module->inc[j].submodule->features[i].flags & LYS_FENABLED) {
-                (*states)[count] = 1;
-            } else {
-                (*states)[count] = 0;
+            if (states) {
+                if (module->inc[j].submodule->features[i].flags & LYS_FENABLED) {
+                    (*states)[count] = 1;
+                } else {
+                    (*states)[count] = 0;
+                }
             }
             count++;
         }