data tree BUGFIX avoid underflow
diff --git a/src/tree_data.c b/src/tree_data.c
index 931e070..4230160 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1281,14 +1281,14 @@
     LY_ERR ret = LY_SUCCESS, r;
     const struct lysc_node *schema;
     struct ly_path_predicate *pred;
-    LY_ARRAY_COUNT_TYPE u, last_u;
+    LY_ARRAY_COUNT_TYPE u, new_count;
 
     assert(path);
 
     /* go through all the compiled nodes */
     LY_ARRAY_FOR(path, u) {
         schema = path[u].node;
-        last_u = u;
+        new_count = u + 1;
         if ((schema->nodetype == LYS_LIST) && (path[u].pred_type == LY_PATH_PREDTYPE_NONE)) {
             if (schema->flags & LYS_KEYLESS) {
                 /* creating a new keyless list instance */
@@ -1303,7 +1303,7 @@
         }
     }
 
-    if ((schema->nodetype == LYS_LEAFLIST) && (path[last_u].pred_type == LY_PATH_PREDTYPE_NONE)) {
+    if ((schema->nodetype == LYS_LEAFLIST) && (path[new_count - 1].pred_type == LY_PATH_PREDTYPE_NONE)) {
         /* parse leafref value into a predicate, if not defined in the path */
         if (!value) {
             value = "";
@@ -1315,8 +1315,8 @@
         }
         if (!r) {
             /* store the new predicate */
-            path[last_u].pred_type = LY_PATH_PREDTYPE_LEAFLIST;
-            LY_ARRAY_NEW_GOTO(schema->module->ctx, path[last_u].predicates, pred, ret, cleanup);
+            path[new_count - 1].pred_type = LY_PATH_PREDTYPE_LEAFLIST;
+            LY_ARRAY_NEW_GOTO(schema->module->ctx, path[new_count - 1].predicates, pred, ret, cleanup);
 
             ret = lyd_value_store(schema->module->ctx, &pred->value, ((struct lysc_node_leaflist *)schema)->type, value,
                     strlen(value), NULL, LY_PREF_JSON, NULL, LYD_HINT_DATA, schema, NULL);
@@ -1325,13 +1325,13 @@
 
             if (schema->flags & LYS_CONFIG_R) {
                 /* creating a new state leaf-list instance */
-                --last_u;
+                --new_count;
             }
         } /* else we have opaq flag and the value is not valid, leave no predicate and then create an opaque node */
     }
 
     /* hide the nodes that should always be created so they are not found */
-    while (last_u + 1 < LY_ARRAY_COUNT(path)) {
+    while (new_count < LY_ARRAY_COUNT(path)) {
         LY_ARRAY_DECREMENT(path);
     }