libyang CHANGE use LY_ARRAY_SIZE_TYPE for iterator variables in LY_TREE_FOR

Because of the change in sized arrays design (780ade2101), also the
iterators and other variables used with LY_TREE_FOR or LY_TREE_SIZE
should be of LY_ARRAY_SIZE_TYPE.

Also the new LY_PRI_ARRAY_SIZE_TYPE was introduced to correctly print
the value of this type in a formatted print functions.
diff --git a/src/context.c b/src/context.c
index 68abcf4..79d672a 100644
--- a/src/context.c
+++ b/src/context.c
@@ -482,7 +482,8 @@
 {
     const struct lys_module *mod;
     struct lysp_include *inc;
-    unsigned int v, u;
+    uint32_t v;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert(submodule);
 
@@ -515,18 +516,17 @@
 API void
 ly_ctx_reset_latests(struct ly_ctx *ctx)
 {
-    unsigned int u,v ;
     struct lys_module *mod;
 
-    for (u = 0; u < ctx->list.count; ++u) {
-        mod = ctx->list.objs[u];
+    for (uint32_t v = 0; v < ctx->list.count; ++v) {
+        mod = ctx->list.objs[v];
         if (mod->latest_revision == 2) {
             mod->latest_revision = 1;
         }
         if (mod->parsed && mod->parsed->includes) {
-            for (v = 0; v < LY_ARRAY_SIZE(mod->parsed->includes); ++v) {
-                if (mod->parsed->includes[v].submodule->latest_revision == 2) {
-                    mod->parsed->includes[v].submodule->latest_revision = 1;
+            for (LY_ARRAY_SIZE_TYPE u = 0; u < LY_ARRAY_SIZE(mod->parsed->includes); ++u) {
+                if (mod->parsed->includes[u].submodule->latest_revision == 2) {
+                    mod->parsed->includes[u].submodule->latest_revision = 1;
                 }
             }
         }
diff --git a/src/parser_stmt.c b/src/parser_stmt.c
index c9fe163..0d19f31 100644
--- a/src/parser_stmt.c
+++ b/src/parser_stmt.c
@@ -65,7 +65,7 @@
  */
 static LY_ERR
 lysp_stmt_ext(struct lys_parser_ctx *ctx, const struct lysp_stmt *stmt, LYEXT_SUBSTMT insubstmt,
-              uint32_t insubstmt_index, struct lysp_ext_instance **exts)
+              LY_ARRAY_SIZE_TYPE insubstmt_index, struct lysp_ext_instance **exts)
 {
     struct lysp_ext_instance *e;
 
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 99b3e87..d260cc0 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -815,7 +815,7 @@
  */
 static LY_ERR
 parse_ext(struct lys_yang_parser_ctx *ctx, const char **data, const char *ext_name, int ext_name_len, LYEXT_SUBSTMT insubstmt,
-          uint32_t insubstmt_index, struct lysp_ext_instance **exts)
+          LY_ARRAY_SIZE_TYPE insubstmt_index, struct lysp_ext_instance **exts)
 {
     LY_ERR ret = LY_SUCCESS;
     char *buf, *word;
diff --git a/src/parser_yin.c b/src/parser_yin.c
index b33b33f..89a77fd 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -622,7 +622,7 @@
 {
     const char **value;
     LY_ARRAY_NEW_RET(ctx->xmlctx->ctx, *values, value, LY_EMEM);
-    uint32_t index = LY_ARRAY_SIZE(*values) - 1;
+    LY_ARRAY_SIZE_TYPE index = LY_ARRAY_SIZE(*values) - 1;
     struct yin_subelement subelems[1] = {
                                             {LY_STMT_EXTENSION_INSTANCE, &index, 0}
                                         };
@@ -2820,7 +2820,7 @@
             /* call responsible function */
             case LY_STMT_EXTENSION_INSTANCE:
                 ret = yin_parse_extension_instance(ctx, kw2lyext_substmt(current_element),
-                                                   (subelem->dest) ? *((uint32_t*)subelem->dest) : 0, exts);
+                                                   (subelem->dest) ? *((LY_ARRAY_SIZE_TYPE*)subelem->dest) : 0, exts);
                 break;
             case LY_STMT_ACTION:
             case LY_STMT_RPC:
@@ -3037,7 +3037,7 @@
 }
 
 LY_ERR
-yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, uint32_t subelem_index,
+yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, LY_ARRAY_SIZE_TYPE subelem_index,
                              struct lysp_ext_instance **exts)
 {
     struct lysp_ext_instance *e;
diff --git a/src/parser_yin.h b/src/parser_yin.h
index 9905581..44b9d24 100644
--- a/src/parser_yin.h
+++ b/src/parser_yin.h
@@ -60,7 +60,7 @@
                                              time to simply check validity of given constraints */
 
 struct yin_subelement {
-    enum ly_stmt type; /**< type of keyword */
+    enum ly_stmt type;      /**< type of keyword */
     void *dest;             /**< meta infromation passed to responsible function (mostly information about where parsed subelement should be stored) */
     uint8_t flags;          /**< describes constraints of subelement can be set to YIN_SUBELEM_MANDATORY, YIN_SUBELEM_UNIQUE, YIN_SUBELEM_FIRST and YIN_SUBELEM_VER2 */
 };
@@ -175,7 +175,7 @@
  *
  * @return LY_ERR values.
  */
-LY_ERR yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, uint32_t subelem_index,
+LY_ERR yin_parse_extension_instance(struct lys_yin_parser_ctx *ctx, LYEXT_SUBSTMT subelem, LY_ARRAY_SIZE_TYPE subelem_index,
                                     struct lysp_ext_instance **exts);
 
 /**
diff --git a/src/plugins_exts_metadata.c b/src/plugins_exts_metadata.c
index 80a116e..b2d405f 100644
--- a/src/plugins_exts_metadata.c
+++ b/src/plugins_exts_metadata.c
@@ -45,7 +45,7 @@
 {
     struct lyext_metadata *annotation;
     struct lysc_module *mod_c;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     /* annotations can appear only at the top level of a YANG module or submodule */
     if (c_ext->parent_type != LYEXT_PAR_MODULE) {
diff --git a/src/plugins_exts_nacm.c b/src/plugins_exts_nacm.c
index 1498cab..fc0c5da 100644
--- a/src/plugins_exts_nacm.c
+++ b/src/plugins_exts_nacm.c
@@ -34,7 +34,7 @@
 {
     struct lysc_node *parent = NULL, *iter;
     struct lysc_ext_instance *inherited;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     static const uint8_t nacm_deny_all = 1;
     static const uint8_t nacm_deny_write = 2;
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 424a08c..290c9fa 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -23,6 +23,7 @@
 
 #include "plugins_types.h"
 #include "dict.h"
+#include "tree.h"
 #include "tree_schema.h"
 #include "tree_schema_internal.h"
 #include "tree_data_internal.h"
@@ -157,7 +158,7 @@
     const char *start, *stop;
     struct lyd_value_prefix *prefixes = NULL;
     const struct lys_module *mod;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     for (stop = start = value; (size_t)(stop - value) < value_len; start = stop) {
         size_t bytes;
@@ -343,7 +344,7 @@
 {
     LY_ERR ret = LY_SUCCESS;
     int rc;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     char *errmsg;
     pcre2_match_data *match_data = NULL;
 
@@ -358,7 +359,7 @@
 
         rc = pcre2_match(patterns[u]->code, (PCRE2_SPTR)str, str_len, 0, PCRE2_ANCHORED | PCRE2_ENDANCHORED, match_data, NULL);
         if (rc == PCRE2_ERROR_NOMATCH) {
-            asprintf(&errmsg, "String \"%.*s\" does not conform to the %u. pattern restriction of its type.",
+            asprintf(&errmsg, "String \"%.*s\" does not conform to the %" LY_PRI_ARRAY_SIZE_TYPE ". pattern restriction of its type.",
                      (int)str_len, str, u + 1);
             *err = ly_err_new(LY_LLERR, LY_ESYS, 0, errmsg, NULL, NULL);
             ret = LY_EVALID;
@@ -386,7 +387,7 @@
 ly_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval,
                        struct ly_err_item **err)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     char *errmsg = NULL;
 
     LY_ARRAY_FOR(range->parts, u) {
@@ -882,7 +883,7 @@
     size_t buf_size = 0;
     char *buf = NULL;
     size_t index;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     char *errmsg = NULL;
     struct lysc_type_bits *type_bits = (struct lysc_type_bits*)type;
     int iscanonical = 1;
@@ -920,7 +921,7 @@
                 /* check that the bit is not disabled */
                 LY_ARRAY_FOR(type_bits->bits[u].iffeatures, v) {
                     if (!lysc_iffeature_value(&type_bits->bits[u].iffeatures[v])) {
-                        asprintf(&errmsg, "Bit \"%s\" is disabled by its %u. if-feature condition.",
+                        asprintf(&errmsg, "Bit \"%s\" is disabled by its %" LY_PRI_ARRAY_SIZE_TYPE ". if-feature condition.",
                                  type_bits->bits[u].name, v + 1);
                         goto error;
                     }
@@ -991,8 +992,8 @@
         if (options & LY_TYPE_OPTS_STORE) {
             /* store data */
             LY_ARRAY_CREATE_GOTO(ctx, storage->bits_items, items_ordered->count, ret, error);
-            for (u = 0; u < items_ordered->count; u++) {
-                storage->bits_items[u] = items_ordered->objs[u];
+            for (uint32_t x = 0; x < items_ordered->count; x++) {
+                storage->bits_items[x] = items_ordered->objs[x];
                 LY_ARRAY_INCREMENT(storage->bits_items);
             }
         }
@@ -1023,7 +1024,7 @@
 static LY_ERR
 ly_type_dup_bits(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_ARRAY_CREATE_RET(ctx, dup->bits_items, LY_ARRAY_SIZE(original->bits_items), LY_EMEM);
     LY_ARRAY_FOR(original->bits_items, u) {
@@ -1060,7 +1061,7 @@
                    const void *UNUSED(context_node), const struct lyd_node *UNUSED(tree),
                    struct lyd_value *storage, const char **canonized, struct ly_err_item **err)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     char *errmsg = NULL;
     struct lysc_type_enum *type_enum = (struct lysc_type_enum*)type;
 
@@ -1076,7 +1077,7 @@
             /* check that the enumeration value is not disabled */
             LY_ARRAY_FOR(type_enum->enums[u].iffeatures, v) {
                 if (!lysc_iffeature_value(&type_enum->enums[u].iffeatures[v])) {
-                    asprintf(&errmsg, "Enumeration \"%s\" is disabled by its %u. if-feature condition.",
+                    asprintf(&errmsg, "Enumeration \"%s\" is disabled by its %" LY_PRI_ARRAY_SIZE_TYPE ". if-feature condition.",
                              type_enum->enums[u].name, v + 1);
                     goto error;
                 }
@@ -1229,7 +1230,7 @@
 API LY_ERR
 ly_type_identity_isderived(struct lysc_ident *base, struct lysc_ident *der)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_ARRAY_FOR(base->derived, u) {
         if (der == base->derived[u]) {
@@ -1258,7 +1259,7 @@
     size_t id_len, prefix_len;
     char *errmsg = NULL;
     const struct lys_module *mod;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_ident *ident;
 
     if (options & LY_TYPE_OPTS_SECOND_CALL) {
@@ -1411,7 +1412,7 @@
     const char *id, *prefix;
     size_t id_len, prefix_len;
     const struct lys_module *mod = NULL;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (ly_parse_nodeid(token, &prefix, &prefix_len, &id, &id_len)) {
         asprintf(errmsg, "Invalid instance-identifier \"%.*s\" value at character %lu (%.*s).",
@@ -1490,7 +1491,7 @@
 ly_type_stored_prefixes_clb(const struct ly_ctx *UNUSED(ctx), const char *prefix, size_t prefix_len, void *private)
 {
     struct lyd_value_prefix *prefixes = (struct lyd_value_prefix*)private;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_ARRAY_FOR(prefixes, u) {
         if (!ly_strncmp(prefixes[u].prefix, prefix, prefix_len)) {
@@ -1598,7 +1599,8 @@
     const struct lysc_node *node_s = NULL;
     const struct lyd_node *node_d = NULL;
     struct lyd_value_prefix *prefixes = NULL;
-    unsigned int u, c;
+    LY_ARRAY_SIZE_TYPE u;
+    uint32_t c;
     struct lyd_value_path *target = NULL, *t;
     struct lyd_value_path_predicate *pred;
     struct ly_set predicates = {0};
@@ -1962,7 +1964,7 @@
 static LY_ERR
 ly_type_compare_instanceid(const struct lyd_value *val1, const struct lyd_value *val2)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
 
     if (val1 == val2) {
         return LY_SUCCESS;
@@ -2012,7 +2014,7 @@
 static const char *
 ly_type_print_instanceid(const struct lyd_value *value, LYD_FORMAT format, ly_clb_get_prefix get_prefix, void *printer, int *dynamic)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     char *result = NULL;
 
     if (!value->target && value->canonical_cache) {
@@ -2113,7 +2115,7 @@
 static LY_ERR
 ly_type_dup_instanceid(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
 
     if (!original->target) {
         return LY_SUCCESS;
@@ -2514,7 +2516,7 @@
                     struct lyd_value *storage, const char **canonized, struct ly_err_item **err)
 {
     LY_ERR ret;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_type_union *type_u = (struct lysc_type_union*)type;
     struct lyd_value_subvalue *subvalue;
     char *errmsg = NULL;
@@ -2642,7 +2644,7 @@
 static LY_ERR
 ly_type_dup_union(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     dup->subvalue = calloc(1, sizeof *dup->subvalue);
     LY_CHECK_ERR_RET(!dup->subvalue, LOGMEM(ctx), LY_EMEM);
@@ -2670,7 +2672,7 @@
 static void
 ly_type_free_union(const struct ly_ctx *ctx, struct lyd_value *value)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (value->subvalue) {
         if (value->subvalue->value) {
diff --git a/src/printer.c b/src/printer.c
index 6b03c01..e9a6041 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -70,7 +70,7 @@
     const struct lysc_node_leaf *leaf;
     const struct lysc_node_leaflist *llist;
     const struct lyd_node_term *term;
-    size_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert(node->schema->nodetype & LYD_NODE_TERM);
     term = (const struct lyd_node_term *)node;
@@ -91,9 +91,9 @@
             return 0;
         }
 
-        LY_ARRAY_FOR(llist->dflts, i) {
+        LY_ARRAY_FOR(llist->dflts, u) {
             /* compare with each possible default value */
-            if (llist->type->plugin->compare(&term->value, llist->dflts[i])) {
+            if (llist->type->plugin->compare(&term->value, llist->dflts[u])) {
                 return 0;
             }
         }
diff --git a/src/printer_xml.c b/src/printer_xml.c
index ce2136a..279d336 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -229,7 +229,7 @@
 {
     const struct ly_attr *attr;
     const char *pref;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_LIST_FOR(node->attr, attr) {
         pref = NULL;
@@ -429,7 +429,7 @@
 {
     LY_ERR ret;
     struct lyd_node *child;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_RET(xml_print_opaq_open(ctx, node));
 
diff --git a/src/printer_yang.c b/src/printer_yang.c
index 159da85..41fb7e9 100755
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -217,9 +217,9 @@
  */
 static void
 yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-                               struct lysp_ext_instance *ext, int *flag, unsigned int count)
+                               struct lysp_ext_instance *ext, int *flag, LY_ARRAY_SIZE_TYPE count)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_stmt *stmt;
     int child_presence;
     const char *argument;
@@ -284,9 +284,9 @@
  */
 static void
 yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-                                 struct lysc_ext_instance *ext, int *flag, unsigned int count)
+                                 struct lysc_ext_instance *ext, int *flag, LY_ARRAY_SIZE_TYPE count)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (!count && ext) {
         count = LY_ARRAY_SIZE(ext);
@@ -308,7 +308,7 @@
 static void
 ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int extflag = 0;
 
     if (!text) {
@@ -442,7 +442,7 @@
 static void
 yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int extflag;
 
     LY_ARRAY_FOR(iff, u) {
@@ -510,7 +510,7 @@
 static void
 yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     int extflag;
 
     LY_ARRAY_FOR(iff, u) {
@@ -540,7 +540,7 @@
 yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
 {
     int flag = 0, flag2 = 0;
-    unsigned int i;
+    LY_ARRAY_SIZE_TYPE u;
 
     ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
     LEVEL++;
@@ -554,9 +554,9 @@
         ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
         LEVEL++;
         if (ext->exts) {
-            i = -1;
-            while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
-                yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
+            u = -1;
+            while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
+                yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
             }
         }
         if ((ext->flags & LYS_YINELEM_MASK) ||
@@ -612,7 +612,7 @@
 yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
 {
     int flag = 0;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
     LEVEL++;
@@ -637,7 +637,7 @@
 yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
 {
     int flag = 0;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
     LEVEL++;
@@ -729,7 +729,7 @@
 yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
 {
     int inner_flag = 0;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (!range) {
         return;
@@ -853,7 +853,7 @@
 static void
 yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int inner_flag;
 
     LY_ARRAY_FOR(items, u) {
@@ -887,7 +887,7 @@
 static void
 yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     ly_print(ctx->out, "%*stype %s", INDENT, type->name);
@@ -943,7 +943,7 @@
 static void
 yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
@@ -1093,7 +1093,7 @@
 static void
 yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *data;
 
@@ -1133,7 +1133,7 @@
 static void
 yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node *data;
 
     if (!inout->nodetype) {
@@ -1167,7 +1167,7 @@
 static void
 yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_node *data;
 
     if (!inout->data) {
@@ -1195,7 +1195,7 @@
 static void
 yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *data;
 
@@ -1236,7 +1236,7 @@
 static void
 yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysc_node *data;
 
@@ -1267,7 +1267,7 @@
 static void
 yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     LYOUT_CHECK(ctx->out);
@@ -1335,7 +1335,7 @@
 static void
 yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
     LEVEL++;
@@ -1374,7 +1374,7 @@
 static void
 yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *child;
     struct lysp_node_container *cont = (struct lysp_node_container *)node;
@@ -1423,7 +1423,7 @@
 static void
 yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysc_node *child;
     struct lysc_node_container *cont = (struct lysc_node_container *)node;
@@ -1549,7 +1549,7 @@
 static void
 yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
 
     yprp_node_common1(ctx, node, NULL);
@@ -1570,7 +1570,7 @@
 static void
 yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
 
     yprc_node_common1(ctx, node, NULL);
@@ -1594,7 +1594,7 @@
 static void
 yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
 
     yprp_node_common1(ctx, node, NULL);
@@ -1636,7 +1636,7 @@
 static void
 yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
 
     yprc_node_common1(ctx, node, NULL);
@@ -1672,7 +1672,7 @@
 static void
 yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *child;
     struct lysp_node_list *list = (struct lysp_node_list *)node;
@@ -1744,7 +1744,7 @@
 static void
 yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     int flag = 0;
     struct lysc_node *child;
     struct lysc_node_list *list = (struct lysc_node_list *)node;
@@ -1808,7 +1808,7 @@
 static void
 yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
@@ -1858,7 +1858,7 @@
 static void
 yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node *child;
 
     ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
@@ -1891,7 +1891,7 @@
 static void
 yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
 
@@ -1915,7 +1915,7 @@
 static void
 yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
 
@@ -1935,7 +1935,7 @@
 static void
 yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
 
@@ -2021,7 +2021,7 @@
 static void
 yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
 {
-    unsigned int v;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_deviate_add *add;
     struct lysp_deviate_rpl *rpl;
     struct lysp_deviate_del *del;
@@ -2053,14 +2053,14 @@
 
             yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
             ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
-            LY_ARRAY_FOR(add->musts, v) {
-                yprp_restr(ctx, &add->musts[v], "must", NULL);
+            LY_ARRAY_FOR(add->musts, u) {
+                yprp_restr(ctx, &add->musts[u], "must", NULL);
             }
-            LY_ARRAY_FOR(add->uniques, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
+            LY_ARRAY_FOR(add->uniques, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, add->uniques[u], add->exts);
             }
-            LY_ARRAY_FOR(add->dflts, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
+            LY_ARRAY_FOR(add->dflts, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, add->dflts[u], add->exts);
             }
             ypr_config(ctx, add->flags, add->exts, NULL);
             ypr_mandatory(ctx, add->flags, add->exts, NULL);
@@ -2104,14 +2104,14 @@
 
             yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
             ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
-            LY_ARRAY_FOR(del->musts, v) {
-                yprp_restr(ctx, &del->musts[v], "must", NULL);
+            LY_ARRAY_FOR(del->musts, u) {
+                yprp_restr(ctx, &del->musts[u], "must", NULL);
             }
-            LY_ARRAY_FOR(del->uniques, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
+            LY_ARRAY_FOR(del->uniques, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, del->uniques[u], del->exts);
             }
-            LY_ARRAY_FOR(del->dflts, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
+            LY_ARRAY_FOR(del->dflts, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, del->dflts[u], del->exts);
             }
         }
 
@@ -2166,7 +2166,7 @@
 LY_ERR
 yang_print_parsed(struct lyout *out, const struct lys_module *module)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node *data;
     struct lysp_module *modp = module->parsed;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
@@ -2291,7 +2291,7 @@
 LY_ERR
 yang_print_compiled(struct lyout *out, const struct lys_module *module)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_node *data;
     struct lysc_module *modc = module->compiled;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
diff --git a/src/printer_yin.c b/src/printer_yin.c
index 7592f02..95dddd3 100644
--- a/src/printer_yin.c
+++ b/src/printer_yin.c
@@ -43,7 +43,7 @@
 #define INDENT (LEVEL)*2,""          /**< indentation parameters for printer functions */
 
 static void yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-                               struct lysp_ext_instance *ext, int *flag, unsigned int count);
+                               struct lysp_ext_instance *ext, int *flag, LY_ARRAY_SIZE_TYPE count);
 
 static void
 ypr_open(struct ypr_ctx *ctx, const char *elem_name, const char *attr_name, const char *attr_value,  int flag)
@@ -96,7 +96,7 @@
 static void
 ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int extflag = 0;
 
     if (!text) {
@@ -229,7 +229,7 @@
 static void
 yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int extflag;
 
     LY_ARRAY_FOR(iff, u) {
@@ -255,7 +255,7 @@
 yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
 {
     int flag = 0, flag2 = 0;
-    unsigned int i;
+    LY_ARRAY_SIZE_TYPE u;
 
     ypr_open(ctx, "extension", "name", ext->name, flag);
     LEVEL++;
@@ -271,10 +271,10 @@
 
         LEVEL++;
         if (ext->exts) {
-            i = -1;
-            while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
+            u = -1;
+            while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
                 ypr_close_parent(ctx, &flag2);
-                yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
+                yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
             }
         }
         if ((ext->flags & LYS_YINELEM_MASK) ||
@@ -314,7 +314,7 @@
 yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
 {
     int flag = 0;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     ypr_open(ctx, "identity", "name", ident->name, flag);
     LEVEL++;
@@ -396,7 +396,7 @@
 static void
 yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int inner_flag;
     (void)flag;
 
@@ -434,13 +434,13 @@
 static void
 yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
 {
+    LY_ARRAY_SIZE_TYPE u;
+    int flag = 0;
+
     if (!ctx || !type) {
         return;
     }
 
-    unsigned int u;
-    int flag = 0;
-
     ypr_open(ctx, "type", "name", type->name, flag);
     LEVEL++;
 
@@ -515,7 +515,7 @@
 static void
 yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *data;
 
@@ -556,7 +556,7 @@
 static void
 yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node *data;
 
     if (!inout->nodetype) {
@@ -590,7 +590,7 @@
 static void
 yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *data;
 
@@ -632,7 +632,7 @@
 static void
 yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     LYOUT_CHECK(ctx->out);
@@ -689,7 +689,7 @@
 static void
 yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *child;
     struct lysp_node_container *cont = (struct lysp_node_container *)node;
@@ -783,7 +783,7 @@
 static void
 yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
 
     int flag = 1;
@@ -805,7 +805,7 @@
 static void
 yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
     int flag = 1;
 
@@ -848,7 +848,7 @@
 static void
 yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node *child;
     struct lysp_node_list *list = (struct lysp_node_list *)node;
@@ -922,7 +922,7 @@
 static void
 yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
 
     ypr_open(ctx, "refine", "target-node", refine->nodeid, flag);
@@ -972,7 +972,7 @@
 static void
 yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_node *child;
 
     ypr_open(ctx, "augment", "target-node", aug->nodeid, 1);
@@ -1005,7 +1005,7 @@
 static void
 yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
 
@@ -1029,7 +1029,7 @@
 static void
 yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     int flag = 0;
     struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
 
@@ -1085,7 +1085,7 @@
 static void
 yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
 {
-    unsigned int v;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysp_deviate_add *add;
     struct lysp_deviate_rpl *rpl;
     struct lysp_deviate_del *del;
@@ -1117,14 +1117,14 @@
 
             yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
             ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
-            LY_ARRAY_FOR(add->musts, v) {
-                yprp_restr(ctx, &add->musts[v], "must", "condition", NULL);
+            LY_ARRAY_FOR(add->musts, u) {
+                yprp_restr(ctx, &add->musts[u], "must", "condition", NULL);
             }
-            LY_ARRAY_FOR(add->uniques, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
+            LY_ARRAY_FOR(add->uniques, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, add->uniques[u], add->exts);
             }
-            LY_ARRAY_FOR(add->dflts, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
+            LY_ARRAY_FOR(add->dflts, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, add->dflts[u], add->exts);
             }
             ypr_config(ctx, add->flags, add->exts, NULL);
             ypr_mandatory(ctx, add->flags, add->exts, NULL);
@@ -1168,14 +1168,14 @@
 
             yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
             ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
-            LY_ARRAY_FOR(del->musts, v) {
-                yprp_restr(ctx, &del->musts[v], "must", "condition", NULL);
+            LY_ARRAY_FOR(del->musts, u) {
+                yprp_restr(ctx, &del->musts[u], "must", "condition", NULL);
             }
-            LY_ARRAY_FOR(del->uniques, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
+            LY_ARRAY_FOR(del->uniques, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, del->uniques[u], del->exts);
             }
-            LY_ARRAY_FOR(del->dflts, v) {
-                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
+            LY_ARRAY_FOR(del->dflts, u) {
+                ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, del->dflts[u], del->exts);
             }
         }
 
@@ -1228,7 +1228,7 @@
 static void
 ypr_xmlns(struct ypr_ctx *ctx, const struct lys_module *module, unsigned int indent)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     ly_print(ctx->out, "%*sxmlns=\"%s\"", indent + INDENT, YIN_NS_URI);
     ly_print(ctx->out, "\n%*sxmlns:%s=\"%s\"", indent + INDENT, module->prefix, module->ns);
@@ -1353,9 +1353,9 @@
  */
 static void
 yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-                               struct lysp_ext_instance *ext, int *flag, unsigned int count)
+                               struct lysp_ext_instance *ext, int *flag, LY_ARRAY_SIZE_TYPE count)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     char *str;
     struct lysp_stmt *stmt;
     const char *argument;
diff --git a/src/tree.h b/src/tree.h
index f2e46ea..d1313b7 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -15,6 +15,8 @@
 #ifndef LY_TREE_H_
 #define LY_TREE_H_
 
+#include "inttypes.h"
+
 #include "tree_data.h"
 
 #ifdef __cplusplus
@@ -23,10 +25,17 @@
 
 /**
  * @brief Type (i.e. size) of the [sized array](@ref sizedarrays)'s size counter.
+ *
+ * To print the value via a print format, use LY_PRI_ARRAY_SIZE_TYPE specifier.
  */
 #define LY_ARRAY_SIZE_TYPE uint64_t
 
 /**
+ * @brief Printing format specifier macro for LY_ARRAY_SIZE_TYPE values.
+ */
+#define LY_PRI_ARRAY_SIZE_TYPE PRIu64
+
+/**
  * @brief Macro selector for other LY_ARRAY_* macros, do not use directly!
  */
 #define LY_ARRAY_SELECT(_1, _2, NAME, ...) NAME
@@ -88,7 +97,7 @@
  *
  *     LY_ARRAY_FOR(ARRAY, INDEX)
  *
- * The ARRAY is again a sized-array to go through, the INDEX is a variable (unsigned integer) for storing iterating ARRAY's index
+ * The ARRAY is again a sized-array to go through, the INDEX is a variable (LY_ARRAY_SIZE_TYPE) for storing iterating ARRAY's index
  * to access the items of ARRAY in the loops. This functionality is provided by LY_ARRAY_FOR_INDEX macro.
  */
 #define LY_ARRAY_FOR(ARRAY, ...) LY_ARRAY_SELECT(__VA_ARGS__, LY_ARRAY_FOR_ITER, LY_ARRAY_FOR_INDEX)(ARRAY, __VA_ARGS__)
diff --git a/src/tree_data.c b/src/tree_data.c
index 51c76db..3841c3a 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1318,15 +1318,15 @@
     LY_ERR ret;
     struct lysc_ext_instance *ant = NULL;
     struct lyd_meta *mt, *last;
-    uint32_t v;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert((parent || meta) && mod);
 
-    LY_ARRAY_FOR(mod->compiled->exts, v) {
-        if (mod->compiled->exts[v].def->plugin == lyext_plugins_internal[LYEXT_PLUGIN_INTERNAL_ANNOTATION].plugin &&
-                !ly_strncmp(mod->compiled->exts[v].argument, name, name_len)) {
+    LY_ARRAY_FOR(mod->compiled->exts, u) {
+        if (mod->compiled->exts[u].def->plugin == lyext_plugins_internal[LYEXT_PLUGIN_INTERNAL_ANNOTATION].plugin &&
+                !ly_strncmp(mod->compiled->exts[u].argument, name, name_len)) {
             /* we have the annotation definition */
-            ant = &mod->compiled->exts[v];
+            ant = &mod->compiled->exts[u];
             break;
         }
     }
@@ -1430,7 +1430,7 @@
 API const struct lyd_node_term *
 lyd_target(struct lyd_value_path *path, const struct lyd_node *tree)
 {
-    uint32_t u, x;
+    LY_ARRAY_SIZE_TYPE u, v;
     const struct lyd_node *start_sibling;
     struct lyd_node *node = NULL;
     uint64_t pos = 1;
@@ -1456,31 +1456,31 @@
 
         /* check predicate if any */
         match = 1;
-        LY_ARRAY_FOR(path[u].predicates, x) {
-            if (path[u].predicates[x].type == 0) {
+        LY_ARRAY_FOR(path[u].predicates, v) {
+            if (path[u].predicates[v].type == 0) {
                 assert(LY_ARRAY_SIZE(path[u].predicates) == 1);
                 /* position predicate */
-                if (pos != path[u].predicates[x].position) {
+                if (pos != path[u].predicates[v].position) {
                     pos++;
                     match = 0;
                 }
-            } else if (path[u].predicates[x].type == 1) {
+            } else if (path[u].predicates[v].type == 1) {
                 /* key-predicate */
-                struct lysc_type *type = ((struct lysc_node_leaf *)path[u].predicates[x].key)->type;
+                struct lysc_type *type = ((struct lysc_node_leaf *)path[u].predicates[v].key)->type;
                 struct lyd_node *key;
 
-                lyd_find_sibling_val(lyd_node_children(node), path[u].predicates[x].key, NULL, 0, &key);
+                lyd_find_sibling_val(lyd_node_children(node), path[u].predicates[v].key, NULL, 0, &key);
                 if (!key) {
                     /* probably error and we shouldn't be here due to previous checks when creating path */
                     match = 0;
-                } else if (type->plugin->compare(&((struct lyd_node_term *)key)->value, path[u].predicates[x].value)) {
+                } else if (type->plugin->compare(&((struct lyd_node_term *)key)->value, path[u].predicates[v].value)) {
                     match = 0;
                 }
-            } else if (path[u].predicates[x].type == 2) {
+            } else if (path[u].predicates[v].type == 2) {
                 /* leaf-list-predicate */
                 struct lysc_type *type = ((struct lysc_node_leaf *)path[u].node)->type;
 
-                if (type->plugin->compare(&((struct lyd_node_term *)node)->value, path[u].predicates[x].value)) {
+                if (type->plugin->compare(&((struct lyd_node_term *)node)->value, path[u].predicates[v].value)) {
                     match = 0;
                 }
             } else {
@@ -1691,7 +1691,7 @@
 {
     LY_ERR ret;
     struct lyd_node *dup = NULL;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_ARG_RET(NULL, node, LY_EINVAL);
 
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index 1d776e6..a8b072c 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -28,7 +28,7 @@
 void
 lyd_value_free_path(const struct ly_ctx *ctx, struct lyd_value_path *path)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
 
     LY_ARRAY_FOR(path, u) {
         LY_ARRAY_FOR(path[u].predicates, v) {
@@ -89,7 +89,7 @@
 ly_free_attr(const struct ly_ctx *ctx, struct ly_attr *attr, int recursive)
 {
     struct ly_attr *iter;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_ARG_RET(NULL, ctx, );
     if (!attr) {
@@ -147,7 +147,7 @@
     struct lyd_node *iter, *next;
     struct lyd_node *children;
     struct lyd_node_opaq *opaq;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert(node);
 
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 176664a..9a2ee1f 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -42,7 +42,7 @@
     int action_flag = 0, notif_flag = 0;
     const struct lysc_action *actions;
     const struct lysc_notif *notifs;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_ARG_RET(NULL, parent || module, NULL);
 
@@ -374,7 +374,8 @@
 lys_feature_change(const struct lys_module *mod, const char *name, int value)
 {
     int all = 0;
-    unsigned int u, changed_count, disabled_count;
+    LY_ARRAY_SIZE_TYPE u, disabled_count;
+    uint32_t changed_count;
     struct lysc_feature *f, **df;
     struct lysc_iffeature *iff;
     struct ly_set *changed;
@@ -535,7 +536,7 @@
 {
     struct lysc_feature *f;
     struct lysc_module *mod;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_ARG_RET(NULL, module, module->compiled, feature, -1);
     mod = module->compiled;
@@ -559,7 +560,7 @@
 API const struct lysc_node *
 lysc_node_is_disabled(const struct lysc_node *node, int recursive)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_CHECK_ARG_RET(NULL, node, NULL);
 
@@ -713,7 +714,7 @@
     struct lysp_import *imp;
     struct lysp_include *inc;
     LY_ERR ret = LY_EINVAL;
-    unsigned int u, i;
+    LY_ARRAY_SIZE_TYPE u, v;
     struct lys_yang_parser_ctx *yangctx = NULL;
     struct lys_yin_parser_ctx *yinctx = NULL;
     struct lys_parser_ctx *pctx;
@@ -824,8 +825,8 @@
             goto error_ctx;
         }
         /* check for importing the same module twice */
-        for (i = 0; i < u; ++i) {
-            if (imp->module == mod->parsed->imports[i].module) {
+        for (v = 0; v < u; ++v) {
+            if (imp->module == mod->parsed->imports[v].module) {
                 LOGVAL(ctx, LY_VLOG_NONE, NULL, LYVE_REFERENCE, "Single revision of the module \"%s\" referred twice.", imp->name);
                 goto error_ctx;
             }
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 3adb1c5..94786b1 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -401,7 +401,7 @@
     struct lysc_ext_instance *compiled;     /**< pointer to the compiled data if any - in case the source format is YIN,
                                                  some of the information (argument) are available only after compilation */
     LYEXT_SUBSTMT insubstmt;                /**< value identifying placement of the extension instance */
-    uint32_t insubstmt_index;               /**< in case the instance is in a substatement, this identifies
+    LY_ARRAY_SIZE_TYPE insubstmt_index;     /**< in case the instance is in a substatement, this identifies
                                                  the index of that substatement */
     uint8_t yin;                            /** flag for YIN source format, can be set to LYS_YIN */
     LYEXT_PARENT parent_type;               /**< type of the parent structure */
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index 1090eb5..c393f4e 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -47,7 +47,7 @@
 #define COMPILE_ARRAY_GOTO(CTX, ARRAY_P, ARRAY_C, ITER, FUNC, RET, GOTO) \
     if (ARRAY_P) { \
         LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, LY_ARRAY_SIZE(ARRAY_P), RET, GOTO); \
-        size_t __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
+        LY_ARRAY_SIZE_TYPE __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
         for (ITER = 0; ITER < LY_ARRAY_SIZE(ARRAY_P); ++ITER) { \
             LY_ARRAY_INCREMENT(ARRAY_C); \
             RET = FUNC(CTX, &(ARRAY_P)[ITER], &(ARRAY_C)[ITER + __array_offset]); \
@@ -58,7 +58,7 @@
 #define COMPILE_ARRAY1_GOTO(CTX, ARRAY_P, ARRAY_C, PARENT, ITER, FUNC, USES_STATUS, RET, GOTO) \
     if (ARRAY_P) { \
         LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, LY_ARRAY_SIZE(ARRAY_P), RET, GOTO); \
-        size_t __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
+        LY_ARRAY_SIZE_TYPE __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
         for (ITER = 0; ITER < LY_ARRAY_SIZE(ARRAY_P); ++ITER) { \
             LY_ARRAY_INCREMENT(ARRAY_C); \
             RET = FUNC(CTX, &(ARRAY_P)[ITER], PARENT, &(ARRAY_C)[ITER + __array_offset], USES_STATUS); \
@@ -69,7 +69,7 @@
 #define COMPILE_EXTS_GOTO(CTX, EXTS_P, EXT_C, PARENT, PARENT_TYPE, RET, GOTO) \
     if (EXTS_P) { \
         LY_ARRAY_CREATE_GOTO((CTX)->ctx, EXT_C, LY_ARRAY_SIZE(EXTS_P), RET, GOTO); \
-        for (uint32_t __exts_iter = 0, __array_offset = LY_ARRAY_SIZE(EXT_C); __exts_iter < LY_ARRAY_SIZE(EXTS_P); ++__exts_iter) { \
+        for (LY_ARRAY_SIZE_TYPE __exts_iter = 0, __array_offset = LY_ARRAY_SIZE(EXT_C); __exts_iter < LY_ARRAY_SIZE(EXTS_P); ++__exts_iter) { \
             LY_ARRAY_INCREMENT(EXT_C); \
             RET = lys_compile_ext(CTX, &(EXTS_P)[__exts_iter], &(EXT_C)[__exts_iter + __array_offset], PARENT, PARENT_TYPE, NULL); \
             LY_CHECK_GOTO(RET != LY_SUCCESS, GOTO); \
@@ -79,7 +79,7 @@
 #define COMPILE_ARRAY_UNIQUE_GOTO(CTX, ARRAY_P, ARRAY_C, ITER, FUNC, RET, GOTO) \
     if (ARRAY_P) { \
         LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, LY_ARRAY_SIZE(ARRAY_P), RET, GOTO); \
-        size_t __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
+        LY_ARRAY_SIZE_TYPE __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
         for (ITER = 0; ITER < LY_ARRAY_SIZE(ARRAY_P); ++ITER) { \
             LY_ARRAY_INCREMENT(ARRAY_C); \
             RET = FUNC(CTX, &(ARRAY_P)[ITER], ARRAY_C, &(ARRAY_C)[ITER + __array_offset]); \
@@ -98,7 +98,7 @@
 #define COMPILE_MEMBER_ARRAY_GOTO(CTX, MEMBER_P, ARRAY_C, FUNC, RET, GOTO) \
     if (MEMBER_P) { \
         LY_ARRAY_CREATE_GOTO((CTX)->ctx, ARRAY_C, 1, RET, GOTO); \
-        size_t __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
+        LY_ARRAY_SIZE_TYPE __array_offset = LY_ARRAY_SIZE(ARRAY_C); \
         LY_ARRAY_INCREMENT(ARRAY_C); \
         RET = FUNC(CTX, MEMBER_P, &(ARRAY_C)[__array_offset]); \
         LY_CHECK_GOTO(RET != LY_SUCCESS, GOTO); \
@@ -106,7 +106,7 @@
 
 #define COMPILE_CHECK_UNIQUENESS_ARRAY(CTX, ARRAY, MEMBER, EXCL, STMT, IDENT) \
     if (ARRAY) { \
-        for (unsigned int u__ = 0; u__ < LY_ARRAY_SIZE(ARRAY); ++u__) { \
+        for (LY_ARRAY_SIZE_TYPE u__ = 0; u__ < LY_ARRAY_SIZE(ARRAY); ++u__) { \
             if (&(ARRAY)[u__] != EXCL && (void*)((ARRAY)[u__].MEMBER) == (void*)(IDENT)) { \
                 LOGVAL((CTX)->ctx, LY_VLOG_STR, (CTX)->path, LY_VCODE_DUPIDENT, IDENT, STMT); \
                 return LY_EVALID; \
@@ -116,7 +116,7 @@
 
 #define COMPILE_CHECK_UNIQUENESS_PARRAY(CTX, ARRAY, MEMBER, EXCL, STMT, IDENT) \
     if (ARRAY) { \
-        for (unsigned int u__ = 0; u__ < LY_ARRAY_SIZE(ARRAY); ++u__) { \
+        for (LY_ARRAY_SIZE_TYPE u__ = 0; u__ < LY_ARRAY_SIZE(ARRAY); ++u__) { \
             if (&(ARRAY)[u__] != EXCL && (void*)((ARRAY)[u__]->MEMBER) == (void*)(IDENT)) { \
                 LOGVAL((CTX)->ctx, LY_VLOG_STR, (CTX)->path, LY_VCODE_DUPIDENT, IDENT, STMT); \
                 return LY_EVALID; \
@@ -271,7 +271,7 @@
 lysc_patterns_dup(struct ly_ctx *ctx, struct lysc_pattern **orig)
 {
     struct lysc_pattern **dup = NULL;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert(orig);
 
@@ -414,6 +414,7 @@
 lys_feature_find(struct lys_module *mod, const char *name, size_t len)
 {
     size_t i;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_feature *f, *flist;
 
     for (i = 0; i < len; ++i) {
@@ -434,8 +435,8 @@
     } else {
         flist = mod->off_features;
     }
-    LY_ARRAY_FOR(flist, i) {
-        f = &flist[i];
+    LY_ARRAY_FOR(flist, u) {
+        f = &flist[u];
         if (!ly_strncmp(f->name, name, len)) {
             return f;
         }
@@ -493,7 +494,8 @@
 {
     LY_ERR ret = LY_EVALID;
     const char *name;
-    unsigned int u;
+    size_t u;
+    LY_ARRAY_SIZE_TYPE v;
     const char *prefixed_name = NULL;
 
     DUP_STRING(ctx->ctx, ext_p->argument, ext->argument);
@@ -515,7 +517,6 @@
             prefixed_name = lydict_insert(ctx->ctx, &ext_p->name[u], 0);
             u = 0;
         } else if (ctx->mod_def->compiled) {
-            unsigned int v;
             LY_ARRAY_FOR(ctx->mod_def->compiled->imports, v) {
                 if (!ly_strncmp(ctx->mod_def->compiled->imports[v].module->ns, ext_p->name, u - 1)) {
                     char *s;
@@ -552,10 +553,10 @@
     name = &prefixed_name[u];
 
     /* find the parsed extension definition there */
-    LY_ARRAY_FOR(ext_mod->parsed->extensions, u) {
-        if (!strcmp(name, ext_mod->parsed->extensions[u].name)) {
+    LY_ARRAY_FOR(ext_mod->parsed->extensions, v) {
+        if (!strcmp(name, ext_mod->parsed->extensions[v].name)) {
             /* compile extension definition and assign it */
-            LY_CHECK_RET(lys_compile_extension(ctx, ext_mod, &ext_mod->parsed->extensions[u], &ext->def));
+            LY_CHECK_RET(lys_compile_extension(ctx, ext_mod, &ext_mod->parsed->extensions[v], &ext->def));
             break;
         }
     }
@@ -985,7 +986,7 @@
 lys_compile_identity_circular_check(struct lysc_ctx *ctx, struct lysc_ident *ident, struct lysc_ident **derived)
 {
     LY_ERR ret = LY_EVALID;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     struct ly_set recursion = {0};
     struct lysc_ident *drv;
 
@@ -1039,7 +1040,7 @@
 static LY_ERR
 lys_compile_identity_bases(struct lysc_ctx *ctx, const char **bases_p,  struct lysc_ident *ident, struct lysc_ident ***bases)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     const char *s, *name;
     struct lys_module *mod;
     struct lysc_ident **idref;
@@ -1119,14 +1120,14 @@
 static LY_ERR
 lys_compile_identities_derived(struct lysc_ctx *ctx, struct lysp_ident *idents_p, struct lysc_ident *idents)
 {
-    unsigned int i;
+    LY_ARRAY_SIZE_TYPE u;
 
-    for (i = 0; i < LY_ARRAY_SIZE(idents_p); ++i) {
-        if (!idents_p[i].bases) {
+    for (u = 0; u < LY_ARRAY_SIZE(idents_p); ++u) {
+        if (!idents_p[u].bases) {
             continue;
         }
-        lysc_update_path(ctx, NULL, idents[i].name);
-        LY_CHECK_RET(lys_compile_identity_bases(ctx, idents_p[i].bases, &idents[i], NULL));
+        lysc_update_path(ctx, NULL, idents[u].name);
+        LY_CHECK_RET(lys_compile_identity_bases(ctx, idents_p[u].bases, &idents[u], NULL));
         lysc_update_path(ctx, NULL, NULL);
     }
     return LY_SUCCESS;
@@ -1135,7 +1136,7 @@
 LY_ERR
 lys_feature_precompile(struct lysc_ctx *ctx_sc, struct ly_ctx *ctx, struct lys_module *module, struct lysp_feature *features_p, struct lysc_feature **features)
 {
-    unsigned int offset = 0, u;
+    LY_ARRAY_SIZE_TYPE offset = 0, u;
     struct lysc_ctx context = {0};
 
     assert(ctx_sc || ctx);
@@ -1191,7 +1192,7 @@
 lys_compile_feature_circular_check(struct lysc_ctx *ctx, struct lysc_feature *feature, struct lysc_feature **depfeatures)
 {
     LY_ERR ret = LY_EVALID;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     struct ly_set recursion = {0};
     struct lysc_feature *drv;
 
@@ -1242,7 +1243,7 @@
 static LY_ERR
 lys_feature_precompile_finish(struct lysc_ctx *ctx, struct lysp_feature *feature_p, struct lysc_feature *features)
 {
-    unsigned int u, v, x;
+    LY_ARRAY_SIZE_TYPE u, v, x;
     struct lysc_feature *feature, **df;
     LY_ERR ret = LY_SUCCESS;
 
@@ -1302,7 +1303,7 @@
 static void
 lys_feature_precompile_revert(struct lysc_ctx *ctx, struct lys_module *mod)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
 
     /* keep the off_features list until the complete lys_module is freed */
     mod->off_features = mod->compiled->features;
@@ -1615,7 +1616,7 @@
     const char *expr;
     struct lysc_range_part *parts = NULL, *part;
     int range_expected = 0, uns;
-    unsigned int parts_done = 0, u, v;
+    LY_ARRAY_SIZE_TYPE parts_done = 0, u, v;
 
     assert(range);
     assert(range_p);
@@ -2055,7 +2056,7 @@
                           struct lysc_pattern **base_patterns, struct lysc_pattern ***patterns)
 {
     struct lysc_pattern **pattern;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     LY_ERR ret = LY_SUCCESS;
 
     /* first, copy the patterns from the base type */
@@ -2134,7 +2135,7 @@
                        struct lysc_type_bitenum_item *base_enums, struct lysc_type_bitenum_item **enums)
 {
     LY_ERR ret = LY_SUCCESS;
-    unsigned int u, v, match = 0;
+    LY_ARRAY_SIZE_TYPE u, v, match = 0;
     int32_t value = 0;
     uint32_t position = 0;
     struct lysc_type_bitenum_item *e, storage;
@@ -2593,7 +2594,7 @@
 {
     LY_ERR ret = LY_EVALID;
     const struct lysc_node *iter;
-    unsigned int u, v, count;
+    LY_ARRAY_SIZE_TYPE u, v, count;
     struct ly_set features = {0};
 
     for (iter = refnode; iter; iter = iter->parent) {
@@ -2798,7 +2799,6 @@
                   struct lysc_type *base,  struct lysc_type **type)
 {
     LY_ERR ret = LY_SUCCESS;
-    unsigned int u, v, additional;
     struct lysc_type_bin *bin;
     struct lysc_type_num *num;
     struct lysc_type_str *str;
@@ -3090,9 +3090,8 @@
                 return LY_EVALID;
             }
             /* compile the type */
-            additional = 0;
             LY_ARRAY_CREATE_RET(ctx->ctx, un->types, LY_ARRAY_SIZE(type_p->types), LY_EVALID);
-            for (u = 0; u < LY_ARRAY_SIZE(type_p->types); ++u) {
+            for (LY_ARRAY_SIZE_TYPE u = 0, additional = 0; u < LY_ARRAY_SIZE(type_p->types); ++u) {
                 LY_CHECK_RET(lys_compile_type(ctx, context_node_p, context_flags, context_mod, context_name, &type_p->types[u], &un->types[u + additional], NULL));
                 if (un->types[u + additional]->basetype == LY_TYPE_UNION) {
                     /* add space for additional types from the union subtype */
@@ -3101,7 +3100,7 @@
                                             lysc_type_free(ctx->ctx, (struct lysc_type*)un_aux), LY_EMEM);
 
                     /* copy subtypes of the subtype union */
-                    for (v = 0; v < LY_ARRAY_SIZE(un_aux->types); ++v) {
+                    for (LY_ARRAY_SIZE_TYPE v = 0; v < LY_ARRAY_SIZE(un_aux->types); ++v) {
                         if (un_aux->types[v]->basetype == LY_TYPE_LEAFREF) {
                             /* duplicate the whole structure because of the instance-specific path resolving for realtype */
                             un->types[u + additional] = calloc(1, sizeof(struct lysc_type_leafref));
@@ -3486,7 +3485,7 @@
                           const char *name, void *exclude)
 {
     const struct lysc_node *iter;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     LY_LIST_FOR(children, iter) {
         if (iter != exclude && iter->module == ctx->mod && !strcmp(name, iter->name)) {
@@ -3713,7 +3712,6 @@
 static LY_ERR
 lys_compile_node_type(struct lysc_ctx *ctx, struct lysp_node *context_node, struct lysp_type *type_p, struct lysc_node_leaf *leaf)
 {
-    unsigned int u;
     struct lysc_node_leaflist *llist = (struct lysc_node_leaflist*)leaf;
 
     LY_CHECK_RET(lys_compile_type(ctx, context_node, leaf->flags, ctx->mod_def->parsed, leaf->name, type_p, &leaf->type,
@@ -3742,6 +3740,7 @@
         /* store to validate the path in the current context at the end of schema compiling when all the nodes are present */
         ly_set_add(&ctx->unres, leaf, 0);
     } else if (leaf->type->basetype == LY_TYPE_UNION) {
+        LY_ARRAY_SIZE_TYPE u;
         LY_ARRAY_FOR(((struct lysc_type_union*)leaf->type)->types, u) {
             if (((struct lysc_type_union*)leaf->type)->types[u]->basetype == LY_TYPE_LEAFREF) {
                 /* store to validate the path in the current context at the end of schema compiling when all the nodes are present */
@@ -3837,7 +3836,7 @@
 {
     struct lysp_node_leaflist *llist_p = (struct lysp_node_leaflist*)node_p;
     struct lysc_node_leaflist *llist = (struct lysc_node_leaflist*)node;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     LY_ERR ret = LY_SUCCESS;
 
     COMPILE_ARRAY_GOTO(ctx, llist_p->musts, llist->musts, u, lys_compile_must, ret, done);
@@ -3939,7 +3938,7 @@
     struct lysc_node *parent;
     const char *keystr, *delim;
     size_t len;
-    unsigned int v;
+    LY_ARRAY_SIZE_TYPE v;
     int config;
     uint16_t flags;
 
@@ -4593,7 +4592,7 @@
 static void
 lys_compile_augment_sort_(struct lysp_augment *aug_p, struct lysp_augment **result)
 {
-    unsigned int v;
+    LY_ARRAY_SIZE_TYPE v;
     size_t len;
 
     len = strlen(aug_p->nodeid);
@@ -4628,8 +4627,7 @@
 lys_compile_augment_sort(struct lysc_ctx *ctx, struct lysp_augment *aug_p, struct lysp_include *inc_p, struct lysp_augment ***augments)
 {
     struct lysp_augment **result = NULL;
-    unsigned int u, v;
-    size_t count = 0;
+    LY_ARRAY_SIZE_TYPE u, v, count = 0;
 
     assert(augments);
 
@@ -4928,7 +4926,8 @@
          .prev = (struct lysc_node*)&context_node_fake,
          .actions = NULL, .notifs = NULL};
     struct lysp_grp *grp = NULL;
-    unsigned int u, v, grp_stack_count;
+    LY_ARRAY_SIZE_TYPE u, v;
+    uint32_t grp_stack_count;
     int found;
     const char *id, *name, *prefix;
     size_t prefix_len, name_len;
@@ -4940,7 +4939,7 @@
     struct ly_set refined = {0};
     struct lysc_when **when, *when_shared;
     struct lysp_augment **augments = NULL;
-    unsigned int actions_index, notifs_index;
+    LY_ARRAY_SIZE_TYPE actions_index = 0, notifs_index = 0;
     struct lysc_notif **notifs = NULL;
     struct lysc_action **actions = NULL;
 
@@ -5125,7 +5124,7 @@
         if (rfn->dflts) {
             if ((node->nodetype != LYS_LEAFLIST) && LY_ARRAY_SIZE(rfn->dflts) > 1) {
                 LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS,
-                       "Invalid refine of default - %s cannot hold %d default values.",
+                       "Invalid refine of default - %s cannot hold %"LY_PRI_ARRAY_SIZE_TYPE" default values.",
                        lys_nodetype2str(node->nodetype), LY_ARRAY_SIZE(rfn->dflts));
                 goto cleanup;
             }
@@ -5346,9 +5345,9 @@
     }
 
     /* do some additional checks of the changed nodes when all the refines are applied */
-    for (u = 0; u < refined.count; ++u) {
-        node = (struct lysc_node*)refined.objs[u];
-        rfn = &uses_p->refines[u];
+    for (uint32_t i = 0; i < refined.count; ++i) {
+        node = (struct lysc_node*)refined.objs[i];
+        rfn = &uses_p->refines[i];
         lysc_update_path(ctx, NULL, rfn->nodeid);
 
         /* check possible conflict with default value (default added, mandatory left true) */
@@ -5831,7 +5830,7 @@
     struct lysp_deviate_add *d_add;
     struct lysp_deviate_del *d_del;
     struct lysp_deviate_rpl *d_rpl;
-    unsigned int u, v, x, y, z;
+    LY_ARRAY_SIZE_TYPE u, v, x, y, z;
     struct lysc_deviation {
         const char *nodeid;
         struct lysc_node *target;      /* target node of the deviation */
@@ -5914,7 +5913,7 @@
 
 #define DEV_CHECK_CARDINALITY(ARRAY, MAX, PROPERTY) \
     if (LY_ARRAY_SIZE(ARRAY) > MAX) { \
-        LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS, "Invalid deviation of %s with too many (%u) %s properties.", \
+        LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS, "Invalid deviation of %s with too many (%"LY_PRI_ARRAY_SIZE_TYPE") %s properties.", \
                lys_nodetype2str(devs[u]->target->nodetype), LY_ARRAY_SIZE(ARRAY), PROPERTY); \
         goto cleanup; \
     }
@@ -6006,7 +6005,7 @@
         /* not-supported */
         if (devs[u]->not_supported) {
             if (LY_ARRAY_SIZE(devs[u]->deviates) > 1) {
-                LOGWRN(ctx->ctx, "Useless multiple (%u) deviates on node \"%s\" since the node is not-supported.",
+                LOGWRN(ctx->ctx, "Useless multiple (%"LY_PRI_ARRAY_SIZE_TYPE") deviates on node \"%s\" since the node is not-supported.",
                        LY_ARRAY_SIZE(devs[u]->deviates), devs[u]->nodeid);
             }
 
@@ -6966,7 +6965,8 @@
 {
     struct lyxp_set tmp_set;
     struct lyxp_set_scnode *xp_scnode;
-    uint32_t i, j, k;
+    uint32_t i, j;
+    LY_ARRAY_SIZE_TYPE u;
     int idx;
     struct lysc_when *when;
     LY_ERR ret = LY_SUCCESS;
@@ -6974,7 +6974,7 @@
     memset(&tmp_set, 0, sizeof tmp_set);
 
     /* prepare in_ctx of the set */
-    for (i = 0; i < set->used; ++i) {
+    for ( i = 0; i < set->used; ++i) {
         xp_scnode = &set->val.scnodes[i];
 
         if (xp_scnode->in_ctx != -1) {
@@ -6999,8 +6999,8 @@
 
         node = xp_scnode->scnode;
         do {
-            LY_ARRAY_FOR(node->when, j) {
-                when = node->when[j];
+            LY_ARRAY_FOR(node->when, u) {
+                when = node->when[u];
                 ret = lyxp_atomize(when->cond, LYD_SCHEMA, when->module, when->context,
                                 when->context ? LYXP_NODE_ELEM : LYXP_NODE_ROOT_CONFIG, &tmp_set, LYXP_SCNODE_SCHEMA);
                 if (ret != LY_SUCCESS) {
@@ -7008,11 +7008,11 @@
                     goto cleanup;
                 }
 
-                for (k = 0; k < tmp_set.used; ++k) {
+                for (j = 0; j < tmp_set.used; ++j) {
                     /* skip roots'n'stuff */
-                    if (tmp_set.val.scnodes[k].type == LYXP_NODE_ELEM) {
+                    if (tmp_set.val.scnodes[j].type == LYXP_NODE_ELEM) {
                         /* try to find this node in our set */
-                        idx = lyxp_set_scnode_dup_node_check(set, tmp_set.val.scnodes[k].scnode, LYXP_NODE_ELEM, -1);
+                        idx = lyxp_set_scnode_dup_node_check(set, tmp_set.val.scnodes[j].scnode, LYXP_NODE_ELEM, -1);
                         if ((idx > -1) && (set->val.scnodes[idx].in_ctx == -1)) {
                             LOGVAL(set->ctx, LY_VLOG_LYSC, node, LY_VCODE_CIRC_WHEN, node->name, set->val.scnodes[idx].scnode->name);
                             ret = LY_EVALID;
@@ -7020,10 +7020,10 @@
                         }
 
                         /* needs to be checked, if in both sets, will be ignored */
-                        tmp_set.val.scnodes[k].in_ctx = 1;
+                        tmp_set.val.scnodes[j].in_ctx = 1;
                     } else {
                         /* no when, nothing to check */
-                        tmp_set.val.scnodes[k].in_ctx = 0;
+                        tmp_set.val.scnodes[j].in_ctx = 0;
                     }
                 }
 
@@ -7054,7 +7054,8 @@
 lys_compile_check_xpath(struct lysc_ctx *ctx, const struct lysc_node *node)
 {
     struct lyxp_set tmp_set;
-    uint32_t i, j;
+    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
     int opts, input_done = 0;
     struct lysc_when **when = NULL;
     struct lysc_must *musts = NULL;
@@ -7105,23 +7106,23 @@
     }
 
     /* check "when" */
-    LY_ARRAY_FOR(when, i) {
-        ret = lyxp_atomize(when[i]->cond, LYD_SCHEMA, when[i]->module, when[i]->context,
-                           when[i]->context ? LYXP_NODE_ELEM : LYXP_NODE_ROOT_CONFIG, &tmp_set, opts);
+    LY_ARRAY_FOR(when, u) {
+        ret = lyxp_atomize(when[u]->cond, LYD_SCHEMA, when[u]->module, when[u]->context,
+                           when[u]->context ? LYXP_NODE_ELEM : LYXP_NODE_ROOT_CONFIG, &tmp_set, opts);
         if (ret != LY_SUCCESS) {
-            LOGVAL(ctx->ctx, LY_VLOG_LYSC, node, LYVE_SEMANTICS, "Invalid when condition \"%s\".", when[i]->cond->expr);
+            LOGVAL(ctx->ctx, LY_VLOG_LYSC, node, LYVE_SEMANTICS, "Invalid when condition \"%s\".", when[u]->cond->expr);
             goto cleanup;
         }
 
         ctx->path[0] = '\0';
         lysc_path((struct lysc_node *)node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE);
-        for (j = 0; j < tmp_set.used; ++j) {
+        for (i = 0; i < tmp_set.used; ++i) {
             /* skip roots'n'stuff */
-            if ((tmp_set.val.scnodes[j].type == LYXP_NODE_ELEM) && (tmp_set.val.scnodes[j].in_ctx != -1)) {
-                struct lysc_node *schema = tmp_set.val.scnodes[j].scnode;
+            if ((tmp_set.val.scnodes[i].type == LYXP_NODE_ELEM) && (tmp_set.val.scnodes[i].in_ctx != -1)) {
+                struct lysc_node *schema = tmp_set.val.scnodes[i].scnode;
 
                 /* XPath expression cannot reference "lower" status than the node that has the definition */
-                ret = lysc_check_status(ctx, when[i]->flags, when[i]->module, node->name, schema->flags, schema->module,
+                ret = lysc_check_status(ctx, when[u]->flags, when[u]->module, node->name, schema->flags, schema->module,
                                         schema->name);
                 LY_CHECK_GOTO(ret, cleanup);
 
@@ -7143,21 +7144,21 @@
 
 check_musts:
     /* check "must" */
-    LY_ARRAY_FOR(musts, i) {
-        ret = lyxp_atomize(musts[i].cond, LYD_SCHEMA, musts[i].module, node, LYXP_NODE_ELEM, &tmp_set, opts);
+    LY_ARRAY_FOR(musts, u) {
+        ret = lyxp_atomize(musts[u].cond, LYD_SCHEMA, musts[u].module, node, LYXP_NODE_ELEM, &tmp_set, opts);
         if (ret != LY_SUCCESS) {
-            LOGVAL(ctx->ctx, LY_VLOG_LYSC, node, LYVE_SEMANTICS, "Invalid must restriction \"%s\".", musts[i].cond->expr);
+            LOGVAL(ctx->ctx, LY_VLOG_LYSC, node, LYVE_SEMANTICS, "Invalid must restriction \"%s\".", musts[u].cond->expr);
             goto cleanup;
         }
 
         ctx->path[0] = '\0';
         lysc_path((struct lysc_node *)node, LYSC_PATH_LOG, ctx->path, LYSC_CTX_BUFSIZE);
-        for (j = 0; j < tmp_set.used; ++j) {
+        for (i = 0; i < tmp_set.used; ++i) {
             /* skip roots'n'stuff */
-            if (tmp_set.val.scnodes[j].type == LYXP_NODE_ELEM) {
+            if (tmp_set.val.scnodes[i].type == LYXP_NODE_ELEM) {
                 /* XPath expression cannot reference "lower" status than the node that has the definition */
-                ret = lysc_check_status(ctx, node->flags, musts[i].module, node->name, tmp_set.val.scnodes[j].scnode->flags,
-                                        tmp_set.val.scnodes[j].scnode->module, tmp_set.val.scnodes[j].scnode->name);
+                ret = lysc_check_status(ctx, node->flags, musts[u].module, node->name, tmp_set.val.scnodes[i].scnode->flags,
+                                        tmp_set.val.scnodes[i].scnode->module, tmp_set.val.scnodes[i].scnode->name);
                 LY_CHECK_GOTO(ret, cleanup);
             }
         }
@@ -7227,7 +7228,8 @@
     struct lysp_augment **augments = NULL;
     struct lysp_grp *grps;
     struct lys_module *m;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
+    uint32_t i;
     LY_ERR ret = LY_SUCCESS;
 
     LY_CHECK_ARG_RET(NULL, mod, mod->parsed, mod->ctx, LY_EINVAL);
@@ -7317,17 +7319,17 @@
     /* for leafref, we need 2 rounds - first detects circular chain by storing the first referred type (which
      * can be also leafref, in case it is already resolved, go through the chain and check that it does not
      * point to the starting leafref type). The second round stores the first non-leafref type for later data validation. */
-    for (u = 0; u < ctx.unres.count; ++u) {
-        if (((struct lysc_node*)ctx.unres.objs[u])->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
-            type = ((struct lysc_node_leaf*)ctx.unres.objs[u])->type;
+    for (i = 0; i < ctx.unres.count; ++i) {
+        if (((struct lysc_node*)ctx.unres.objs[i])->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
+            type = ((struct lysc_node_leaf*)ctx.unres.objs[i])->type;
             if (type->basetype == LY_TYPE_LEAFREF) {
                 /* validate the path */
-                LY_CHECK_GOTO(ret = lys_compile_leafref_validate(&ctx, ((struct lysc_node*)ctx.unres.objs[u]), (struct lysc_type_leafref*)type, NULL), error);
+                LY_CHECK_GOTO(ret = lys_compile_leafref_validate(&ctx, ((struct lysc_node*)ctx.unres.objs[i]), (struct lysc_type_leafref*)type, NULL), error);
             } else if (type->basetype == LY_TYPE_UNION) {
                 LY_ARRAY_FOR(((struct lysc_type_union*)type)->types, v) {
                     if (((struct lysc_type_union*)type)->types[v]->basetype == LY_TYPE_LEAFREF) {
                         /* validate the path */
-                        ret = lys_compile_leafref_validate(&ctx, ((struct lysc_node*)ctx.unres.objs[u]),
+                        ret = lys_compile_leafref_validate(&ctx, ((struct lysc_node*)ctx.unres.objs[i]),
                                                            (struct lysc_type_leafref*)((struct lysc_type_union*)type)->types[v], NULL);
                         LY_CHECK_GOTO(ret, error);
                     }
@@ -7336,11 +7338,11 @@
         }
 
         /* check xpath */
-        LY_CHECK_GOTO(ret = lys_compile_check_xpath(&ctx, ctx.unres.objs[u]), error);
+        LY_CHECK_GOTO(ret = lys_compile_check_xpath(&ctx, ctx.unres.objs[i]), error);
     }
-    for (u = 0; u < ctx.unres.count; ++u) {
-        if (((struct lysc_node*)ctx.unres.objs[u])->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
-            type = ((struct lysc_node_leaf*)ctx.unres.objs[u])->type;
+    for (i = 0; i < ctx.unres.count; ++i) {
+        if (((struct lysc_node*)ctx.unres.objs[i])->nodetype & (LYS_LEAF | LYS_LEAFLIST)) {
+            type = ((struct lysc_node_leaf*)ctx.unres.objs[i])->type;
             if (type->basetype == LY_TYPE_LEAFREF) {
                 /* store pointer to the real type */
                 for (typeiter = ((struct lysc_type_leafref*)type)->realtype;
@@ -7362,9 +7364,9 @@
     }
 
     /* finish incomplete default values compilation */
-    for (u = 0; u < ctx.dflts.count; ++u) {
+    for (i = 0; i < ctx.dflts.count; ++i) {
         struct ly_err_item *err = NULL;
-        struct lysc_incomplete_dflt *r = ctx.dflts.objs[u];
+        struct lysc_incomplete_dflt *r = ctx.dflts.objs[i];
         ret = r->dflt->realtype->plugin->store(ctx.ctx, r->dflt->realtype, r->dflt->original, strlen(r->dflt->original),
                                                LY_TYPE_OPTS_SCHEMA | LY_TYPE_OPTS_STORE | LY_TYPE_OPTS_SECOND_CALL, lys_resolve_prefix,
                                                (void*)r->dflt_mod, LYD_XML, r->context_node, NULL, r->dflt, NULL, &err);
@@ -7432,8 +7434,8 @@
 
     if (!(ctx.options & LYSC_OPT_INTERNAL)) {
         /* remove flag of the modules implemented by dependency */
-        for (u = 0; u < ctx.ctx->list.count; ++u) {
-            m = ctx.ctx->list.objs[u];
+        for (i = 0; i < ctx.ctx->list.count; ++i) {
+            m = ctx.ctx->list.objs[i];
             if (m->implemented == 2) {
                 m->implemented = 1;
             }
@@ -7454,8 +7456,8 @@
     mod->compiled = NULL;
 
     /* revert compilation of modules implemented by dependency */
-    for (u = 0; u < ctx.ctx->list.count; ++u) {
-        m = ctx.ctx->list.objs[u];
+    for (i = 0; i < ctx.ctx->list.count; ++i) {
+        m = ctx.ctx->list.objs[i];
         if ((m->implemented == 2) && m->compiled) {
             /* revert features list to the precompiled state */
             lys_feature_precompile_revert(&ctx, m);
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 4bb2bf5..c6406bf 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -726,7 +726,7 @@
 static void
 lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     FREE_ARRAY(ctx, node->musts, lysc_must_free);
     if (node->type) {
@@ -745,7 +745,7 @@
 static void
 lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     struct lysc_node *child, *child_next;
 
     LY_LIST_FOR_SAFE(node->child, child_next, child) {
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 255e512..565faf1 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -264,7 +264,7 @@
 lysp_type_match(const char *name, struct lysp_node *node)
 {
     const struct lysp_tpdf *typedefs;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     typedefs = lysp_node_typedefs(node);
     LY_ARRAY_FOR(typedefs, u) {
@@ -357,7 +357,7 @@
 {
     const char *str, *name;
     struct lysp_tpdf *typedefs;
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
 
     assert(id);
     assert(start_module);
@@ -466,7 +466,7 @@
     uint32_t hash;
     size_t name_len;
     const char *name;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     const struct lysp_tpdf *typedefs;
 
     assert(ctx);
@@ -532,7 +532,7 @@
 lysp_parse_finalize_reallocated(struct lys_parser_ctx *ctx, struct lysp_grp *groupings, struct lysp_augment *augments,
                                 struct lysp_action *actions, struct lysp_notif *notifs)
 {
-    unsigned int u, v;
+    LY_ARRAY_SIZE_TYPE u, v;
     struct lysp_node *child;
 
     /* finalize parent pointers to the reallocated items */
@@ -625,28 +625,29 @@
     struct hash_table *ids_global;
     struct hash_table *ids_scoped;
     const struct lysp_tpdf *typedefs;
-    unsigned int i, u;
+    LY_ARRAY_SIZE_TYPE u, v;
+    uint32_t i;
     LY_ERR ret = LY_EVALID;
 
     /* check name collisions - typedefs and groupings */
     ids_global = lyht_new(8, sizeof(char*), lysp_id_cmp, NULL, 1);
     ids_scoped = lyht_new(8, sizeof(char*), lysp_id_cmp, NULL, 1);
-    LY_ARRAY_FOR(mod->typedefs, i) {
-        if (lysp_check_typedef(ctx, NULL, &mod->typedefs[i], ids_global, ids_scoped)) {
+    LY_ARRAY_FOR(mod->typedefs, v) {
+        if (lysp_check_typedef(ctx, NULL, &mod->typedefs[v], ids_global, ids_scoped)) {
             goto cleanup;
         }
     }
-    LY_ARRAY_FOR(mod->includes, i) {
-        LY_ARRAY_FOR(mod->includes[i].submodule->typedefs, u) {
-            if (lysp_check_typedef(ctx, NULL, &mod->includes[i].submodule->typedefs[u], ids_global, ids_scoped)) {
+    LY_ARRAY_FOR(mod->includes, v) {
+        LY_ARRAY_FOR(mod->includes[v].submodule->typedefs, u) {
+            if (lysp_check_typedef(ctx, NULL, &mod->includes[v].submodule->typedefs[u], ids_global, ids_scoped)) {
                 goto cleanup;
             }
         }
     }
-    for (u = 0; u < ctx->tpdfs_nodes.count; ++u) {
-        typedefs = lysp_node_typedefs((struct lysp_node *)ctx->tpdfs_nodes.objs[u]);
-        LY_ARRAY_FOR(typedefs, i) {
-            if (lysp_check_typedef(ctx, (struct lysp_node *)ctx->tpdfs_nodes.objs[u], &typedefs[i], ids_global, ids_scoped)) {
+    for (i = 0; i < ctx->tpdfs_nodes.count; ++i) {
+        typedefs = lysp_node_typedefs((struct lysp_node *)ctx->tpdfs_nodes.objs[i]);
+        LY_ARRAY_FOR(typedefs, u) {
+            if (lysp_check_typedef(ctx, (struct lysp_node *)ctx->tpdfs_nodes.objs[i], &typedefs[u], ids_global, ids_scoped)) {
                 goto cleanup;
             }
         }
@@ -1062,7 +1063,7 @@
 const char *
 lys_prefix_find_module(const struct lys_module *mod, const struct lys_module *import)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (import == mod) {
         return mod->prefix;
@@ -1628,8 +1629,8 @@
     return result;
 }
 
-unsigned int
-lysp_ext_instance_iter(struct lysp_ext_instance *ext, unsigned int index, LYEXT_SUBSTMT substmt)
+LY_ARRAY_SIZE_TYPE
+lysp_ext_instance_iter(struct lysp_ext_instance *ext, LY_ARRAY_SIZE_TYPE index, LYEXT_SUBSTMT substmt)
 {
     LY_CHECK_ARG_RET(NULL, ext, LY_EINVAL);
 
@@ -1654,7 +1655,7 @@
 lys_get_prefix(const struct lys_module *mod, void *private)
 {
     struct lys_module *context_mod = (struct lys_module*)private;
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (context_mod == mod) {
         return context_mod->prefix;
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index c99eb1a..9f291f3 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -63,8 +63,8 @@
  */
 #define CHECK_UNIQUENESS(CTX, ARRAY, MEMBER, STMT, IDENT) \
     if (ARRAY) { \
-        for (unsigned int u = 0; u < LY_ARRAY_SIZE(ARRAY) - 1; ++u) { \
-            if (!strcmp((ARRAY)[u].MEMBER, IDENT)) { \
+        for (LY_ARRAY_SIZE_TYPE u_ = 0; u_ < LY_ARRAY_SIZE(ARRAY) - 1; ++u_) { \
+            if (!strcmp((ARRAY)[u_].MEMBER, IDENT)) { \
                 LOGVAL_PARSER(CTX, LY_VCODE_DUPIDENT, IDENT, STMT); \
                 return LY_EVALID; \
             } \
@@ -391,7 +391,7 @@
  *            #LYEXT_SUBSTMT_ALL to go through all the extensions in the array
  * @result index in the ext array, LY_ARRAY_SIZE(ext) value if not present.
  */
-unsigned int lysp_ext_instance_iter(struct lysp_ext_instance *ext, unsigned int index, LYEXT_SUBSTMT substmt);
+LY_ARRAY_SIZE_TYPE lysp_ext_instance_iter(struct lysp_ext_instance *ext, LY_ARRAY_SIZE_TYPE index, LYEXT_SUBSTMT substmt);
 
 /**
  * @brief Get the covering schema module structure for the given parsed module structure.
@@ -691,7 +691,7 @@
  * @brief Macro to free [sized array](@ref sizedarrays) of items using the provided free function. The ARRAY itself is also freed,
  * but the memory is not sanitized.
  */
-#define FREE_ARRAY(CTX, ARRAY, FUNC) {uint64_t c__; LY_ARRAY_FOR(ARRAY, c__){FUNC(CTX, &(ARRAY)[c__]);}LY_ARRAY_FREE(ARRAY);}
+#define FREE_ARRAY(CTX, ARRAY, FUNC) {LY_ARRAY_SIZE_TYPE c__; LY_ARRAY_FOR(ARRAY, c__){FUNC(CTX, &(ARRAY)[c__]);}LY_ARRAY_FREE(ARRAY);}
 
 /**
  * @brief Macro to free the specified MEMBER of a structure using the provided free function. The memory is not sanitized.
@@ -702,7 +702,7 @@
  * @brief Macro to free [sized array](@ref sizedarrays) of strings stored in the context's dictionary. The ARRAY itself is also freed,
  * but the memory is not sanitized.
  */
-#define FREE_STRINGS(CTX, ARRAY) {uint64_t c__; LY_ARRAY_FOR(ARRAY, c__){FREE_STRING(CTX, ARRAY[c__]);}LY_ARRAY_FREE(ARRAY);}
+#define FREE_STRINGS(CTX, ARRAY) {LY_ARRAY_SIZE_TYPE c__; LY_ARRAY_FOR(ARRAY, c__){FREE_STRING(CTX, ARRAY[c__]);}LY_ARRAY_FREE(ARRAY);}
 
 /**
  * @brief Free the parsed submodule structure.
diff --git a/src/validation.c b/src/validation.c
index c7c1ae8..69a2639 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -132,24 +132,24 @@
                    LYD_FORMAT format, ly_clb_resolve_prefix get_prefix_clb, void *parser_data)
 {
     LY_ERR ret = LY_SUCCESS;
-    uint32_t u;
+    uint32_t i;
 
     if (node_when) {
         /* evaluate all when conditions */
         uint32_t prev_count;
         do {
             prev_count = node_when->count;
-            u = 0;
-            while (u < node_when->count) {
+            i = 0;
+            while (i < node_when->count) {
                 /* evaluate all when expressions that affect this node's existence */
-                struct lyd_node *node = (struct lyd_node *)node_when->objs[u];
+                struct lyd_node *node = (struct lyd_node *)node_when->objs[i];
                 const struct lysc_node *schema = node->schema;
                 int unres_when = 0;
 
                 do {
-                    uint32_t i;
-                    LY_ARRAY_FOR(schema->when, i) {
-                        ret = lyd_validate_when(tree, node, schema->when[i]);
+                    LY_ARRAY_SIZE_TYPE u;
+                    LY_ARRAY_FOR(schema->when, u) {
+                        ret = lyd_validate_when(tree, node, schema->when[u]);
                         if (ret) {
                             break;
                         }
@@ -167,10 +167,10 @@
 
                 if (unres_when) {
                     /* keep in set and go to the next node */
-                    ++u;
+                    ++i;
                 } else {
                     /* remove this node from the set */
-                    ly_set_rm_index(node_when, u, NULL);
+                    ly_set_rm_index(node_when, i, NULL);
                 }
             }
 
@@ -183,11 +183,11 @@
 
     if (node_types && node_types->count) {
         /* finish incompletely validated terminal values (traverse from the end for efficient set removal) */
-        u = node_types->count;
+        i = node_types->count;
         do {
-            --u;
+            --i;
 
-            struct lyd_node_term *node = (struct lyd_node_term *)node_types->objs[u];
+            struct lyd_node_term *node = (struct lyd_node_term *)node_types->objs[i];
 
             /* validate and store the value of the node */
             ret = lyd_value_parse(node, node->value.original, strlen(node->value.original), 0, 1, get_prefix_clb,
@@ -195,17 +195,17 @@
             LY_CHECK_RET(ret);
 
             /* remove this node from the set */
-            ly_set_rm_index(node_types, u, NULL);
-        } while (u);
+            ly_set_rm_index(node_types, i, NULL);
+        } while (i);
     }
 
     if (meta_types && meta_types->count) {
         /* ... and metadata values */
-        u = meta_types->count;
+        i = meta_types->count;
         do {
-            --u;
+            --i;
 
-            struct lyd_meta *meta = (struct lyd_meta *)meta_types->objs[u];
+            struct lyd_meta *meta = (struct lyd_meta *)meta_types->objs[i];
 
             /* validate and store the value of the metadata */
             ret = lyd_value_parse_meta(meta->parent->schema->module->ctx, meta, meta->value.original,
@@ -213,8 +213,8 @@
             LY_CHECK_RET(ret);
 
             /* remove this attr from the set */
-            ly_set_rm_index(meta_types, u, NULL);
-        } while (u);
+            ly_set_rm_index(meta_types, i, NULL);
+        } while (i);
     }
 
     return ret;
@@ -535,13 +535,13 @@
     struct lyd_node *diter, *first, *second;
     struct lyd_value *val1, *val2;
     char *path1, *path2, *uniq_str, *ptr;
-    uint32_t i, j, action;
+    LY_ARRAY_SIZE_TYPE u, v, action;
 
     assert(val1_p && val2_p);
 
     first = *((struct lyd_node **)val1_p);
     second = *((struct lyd_node **)val2_p);
-    action = (uintptr_t)cb_data;
+    action = (LY_ARRAY_SIZE_TYPE)cb_data;
 
     assert(first && (first->schema->nodetype == LYS_LIST));
     assert(second && (second->schema == first->schema));
@@ -552,30 +552,30 @@
 
     /* compare unique leaves */
     if (action > 0) {
-        i = action - 1;
-        if (i < LY_ARRAY_SIZE(slist->uniques)) {
+        u = action - 1;
+        if (u < LY_ARRAY_SIZE(slist->uniques)) {
             goto uniquecheck;
         }
     }
-    LY_ARRAY_FOR(slist->uniques, i) {
+    LY_ARRAY_FOR(slist->uniques, u) {
 uniquecheck:
-        LY_ARRAY_FOR(slist->uniques[i], j) {
+        LY_ARRAY_FOR(slist->uniques[u], v) {
             /* first */
-            diter = lyd_val_uniq_find_leaf(slist->uniques[i][j], first);
+            diter = lyd_val_uniq_find_leaf(slist->uniques[u][v], first);
             if (diter) {
                 val1 = &((struct lyd_node_term *)diter)->value;
             } else {
                 /* use default value */
-                val1 = slist->uniques[i][j]->dflt;
+                val1 = slist->uniques[u][v]->dflt;
             }
 
             /* second */
-            diter = lyd_val_uniq_find_leaf(slist->uniques[i][j], second);
+            diter = lyd_val_uniq_find_leaf(slist->uniques[u][v], second);
             if (diter) {
                 val2 = &((struct lyd_node_term *)diter)->value;
             } else {
                 /* use default value */
-                val2 = slist->uniques[i][j]->dflt;
+                val2 = slist->uniques[u][v]->dflt;
             }
 
             if (!val1 || !val2 || val1->realtype->plugin->compare(val1, val2)) {
@@ -583,7 +583,7 @@
                 break;
             }
         }
-        if (j && (j == LY_ARRAY_SIZE(slist->uniques[i]))) {
+        if (v && (v == LY_ARRAY_SIZE(slist->uniques[u]))) {
             /* all unique leafs are the same in this set, create this nice error */
             path1 = lyd_path(first, LYD_PATH_LOG, NULL, 0);
             path2 = lyd_path(second, LYD_PATH_LOG, NULL, 0);
@@ -592,12 +592,12 @@
             uniq_str = malloc(1024);
             uniq_str[0] = '\0';
             ptr = uniq_str;
-            LY_ARRAY_FOR(slist->uniques[i], j) {
-                if (j) {
+            LY_ARRAY_FOR(slist->uniques[u], v) {
+                if (v) {
                     strcpy(ptr, " ");
                     ++ptr;
                 }
-                ptr = lysc_path_until((struct lysc_node *)slist->uniques[i][j], (struct lysc_node *)slist, LYSC_PATH_LOG,
+                ptr = lysc_path_until((struct lysc_node *)slist->uniques[u][v], (struct lysc_node *)slist, LYSC_PATH_LOG,
                                       ptr, 1024 - (ptr - uniq_str));
                 if (!ptr) {
                     /* path will be incomplete, whatever */
@@ -628,9 +628,9 @@
 {
     const struct lyd_node *diter;
     struct ly_set *set;
-    uint32_t i, j, n = 0;
+    LY_ARRAY_SIZE_TYPE u, v, x = 0;
     LY_ERR ret = LY_SUCCESS;
-    uint32_t hash, u, usize = 0;
+    uint32_t hash, i, size = 0;
     int dynamic;
     const char *str;
     struct hash_table **uniqtables = NULL;
@@ -658,36 +658,36 @@
     } else if (set->count > 2) {
         /* use hashes for comparison */
         /* first, allocate the table, the size depends on number of items in the set */
-        for (u = 31; u > 0; u--) {
-            usize = set->count << u;
-            usize = usize >> u;
-            if (usize == set->count) {
+        for (i = 31; i > 0; i--) {
+            size = set->count << i;
+            size = size >> i;
+            if (size == set->count) {
                 break;
             }
         }
-        LY_CHECK_ERR_GOTO(!u, LOGINT(ctx); ret = LY_EINT, cleanup);
-        u = 32 - u;
-        usize = 1 << u;
+        LY_CHECK_ERR_GOTO(!i, LOGINT(ctx); ret = LY_EINT, cleanup);
+        i = 32 - i;
+        size = 1 << i;
 
         uniqtables = malloc(LY_ARRAY_SIZE(uniques) * sizeof *uniqtables);
         LY_CHECK_ERR_GOTO(!uniqtables, LOGMEM(ctx); ret = LY_EMEM, cleanup);
-        n = LY_ARRAY_SIZE(uniques);
-        for (j = 0; j < n; j++) {
-            uniqtables[j] = lyht_new(usize, sizeof(struct lyd_node *), lyd_val_uniq_list_equal, (void *)(j + 1L), 0);
-            LY_CHECK_ERR_GOTO(!uniqtables[j], LOGMEM(ctx); ret = LY_EMEM, cleanup);
+        x = LY_ARRAY_SIZE(uniques);
+        for (v = 0; v < x; v++) {
+            uniqtables[v] = lyht_new(size, sizeof(struct lyd_node *), lyd_val_uniq_list_equal, (void *)(v + 1L), 0);
+            LY_CHECK_ERR_GOTO(!uniqtables[v], LOGMEM(ctx); ret = LY_EMEM, cleanup);
         }
 
-        for (u = 0; u < set->count; u++) {
+        for (i = 0; i < set->count; i++) {
             /* loop for unique - get the hash for the instances */
-            for (i = 0; i < n; i++) {
+            for (u = 0; u < x; u++) {
                 val = NULL;
-                for (j = hash = 0; j < LY_ARRAY_SIZE(uniques[i]); j++) {
-                    diter = lyd_val_uniq_find_leaf(uniques[i][j], set->objs[u]);
+                for (v = hash = 0; v < LY_ARRAY_SIZE(uniques[u]); v++) {
+                    diter = lyd_val_uniq_find_leaf(uniques[u][v], set->objs[i]);
                     if (diter) {
                         val = &((struct lyd_node_term *)diter)->value;
                     } else {
                         /* use default value */
-                        val = uniques[i][j]->dflt;
+                        val = uniques[u][v]->dflt;
                     }
                     if (!val) {
                         /* unique item not present nor has default value */
@@ -710,7 +710,7 @@
                 hash = dict_hash_multi(hash, NULL, 0);
 
                 /* insert into the hashtable */
-                ret = lyht_insert(uniqtables[i], &set->objs[u], hash, NULL);
+                ret = lyht_insert(uniqtables[u], &set->objs[i], hash, NULL);
                 if (ret == LY_EEXIST) {
                     /* instance duplication */
                     ret = LY_EVALID;
@@ -722,12 +722,12 @@
 
 cleanup:
     ly_set_free(set, NULL);
-    for (j = 0; j < n; j++) {
-        if (!uniqtables[j]) {
+    for (v = 0; v < x; v++) {
+        if (!uniqtables[v]) {
             /* failed when allocating uniquetables[j], following j are not allocated */
             break;
         }
-        lyht_free(uniqtables[j]);
+        lyht_free(uniqtables[v]);
     }
     free(uniqtables);
 
@@ -801,7 +801,7 @@
     struct lyxp_set xp_set;
     struct lysc_must *musts;
     const struct lyd_node *tree;
-    uint32_t u;
+    LY_ARRAY_SIZE_TYPE u;
 
     switch (node->schema->nodetype) {
     case LYS_CONTAINER:
@@ -945,7 +945,7 @@
     const struct lysc_node *iter = NULL;
     struct lyd_node *node;
     struct lyd_value **dflts;
-    size_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     assert(first && (parent || sparent || mod) && node_types && node_when);
 
@@ -1005,8 +1005,8 @@
             if (((struct lysc_node_leaflist *)iter)->dflts && lyd_find_sibling_next2(*first, iter, NULL, 0, NULL)) {
                 /* create all default leaf-lists */
                 dflts = ((struct lysc_node_leaflist *)iter)->dflts;
-                LY_ARRAY_FOR(dflts, i) {
-                    ret = lyd_create_term2(iter, dflts[i], &node);
+                LY_ARRAY_FOR(dflts, u) {
+                    ret = lyd_create_term2(iter, dflts[u], &node);
                     if (ret == LY_EINCOMPLETE) {
                         /* remember to resolve type */
                         ly_set_add(node_types, node, LY_SET_OPT_USEASLIST);
diff --git a/src/xml.c b/src/xml.c
index 8a9a3da..f376672 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -1064,7 +1064,8 @@
 lyxml_get_prefixes(struct lyxml_ctx *xmlctx, const char *value, size_t value_len, struct ly_prefix **val_prefs)
 {
     LY_ERR ret;
-    uint32_t u, c;
+    LY_ARRAY_SIZE_TYPE u;
+    uint32_t c;
     const struct lyxml_ns *ns;
     const char *start, *stop;
     struct ly_prefix *prefixes = NULL;
@@ -1118,7 +1119,7 @@
 lyxml_value_compare(const char *value1, const struct ly_prefix *prefs1, const char *value2, const struct ly_prefix *prefs2)
 {
     const char *ptr1, *ptr2, *ns1, *ns2;
-    uint32_t u1, u2;
+    LY_ARRAY_SIZE_TYPE u1, u2;
     int len;
 
     if (!value1 && !value2) {
diff --git a/src/xpath.c b/src/xpath.c
index e84bad9..bd57bd4 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -2890,7 +2890,7 @@
 {
     struct lysc_type_union *uni;
     int ret;
-    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     switch (type->basetype) {
     case LY_TYPE_DEC64:
@@ -2905,8 +2905,8 @@
         return 1;
     case LY_TYPE_UNION:
         uni = (struct lysc_type_union *)type;
-        LY_ARRAY_FOR(uni->types, i) {
-            ret = warn_is_numeric_type(uni->types[i]);
+        LY_ARRAY_FOR(uni->types, u) {
+            ret = warn_is_numeric_type(uni->types[u]);
             if (ret) {
                 /* found a suitable type */
                 return 1;
@@ -2932,7 +2932,7 @@
 {
     struct lysc_type_union *uni;
     int ret;
-    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     switch (type->basetype) {
     case LY_TYPE_BITS:
@@ -2943,8 +2943,8 @@
         return 1;
     case LY_TYPE_UNION:
         uni = (struct lysc_type_union *)type;
-        LY_ARRAY_FOR(uni->types, i) {
-            ret = warn_is_string_type(uni->types[i]);
+        LY_ARRAY_FOR(uni->types, u) {
+            ret = warn_is_string_type(uni->types[u]);
             if (ret) {
                 /* found a suitable type */
                 return 1;
@@ -2971,14 +2971,14 @@
 {
     struct lysc_type_union *uni;
     int ret;
-    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (type->basetype == base) {
         return 1;
     } else if (type->basetype == LY_TYPE_UNION) {
         uni = (struct lysc_type_union *)type;
-        LY_ARRAY_FOR(uni->types, i) {
-            ret = warn_is_specific_type(uni->types[i], base);
+        LY_ARRAY_FOR(uni->types, u) {
+            ret = warn_is_specific_type(uni->types[u], base);
             if (ret) {
                 /* found a suitable type */
                 return 1;
@@ -3005,7 +3005,7 @@
 {
     struct lysc_type_union *uni;
     int found = 0;
-    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     switch (type->basetype) {
     case LY_TYPE_UNION:
@@ -3013,11 +3013,11 @@
         if (!prev_type) {
             return uni->types[0];
         }
-        LY_ARRAY_FOR(uni->types, i) {
+        LY_ARRAY_FOR(uni->types, u) {
             if (found) {
-                return uni->types[i];
+                return uni->types[u];
             }
-            if (prev_type == uni->types[i]) {
+            if (prev_type == uni->types[u]) {
                 found = 1;
             }
         }
@@ -3212,7 +3212,7 @@
     struct lysc_node_leaf *sleaf;
     struct lysc_type_bits *bits;
     LY_ERR rc = LY_SUCCESS;
-    uint32_t i;
+    LY_ARRAY_SIZE_TYPE u;
 
     if (options & LYXP_SCNODE_ALL) {
         if ((args[0]->type != LYXP_SET_SCNODE_SET) || !(sleaf = (struct lysc_node_leaf *)warn_get_scnode_in_ctx(args[0]))) {
@@ -3247,8 +3247,8 @@
         if ((leaf->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST))
                 && (((struct lysc_node_leaf *)leaf->schema)->type->basetype == LY_TYPE_BITS)) {
             bits = (struct lysc_type_bits *)((struct lysc_node_leaf *)leaf->schema)->type;
-            LY_ARRAY_FOR(bits->bits, i) {
-                if (!strcmp(bits->bits[i].name, args[1]->val.str)) {
+            LY_ARRAY_FOR(bits->bits, u) {
+                if (!strcmp(bits->bits[u].name, args[1]->val.str)) {
                     set_fill_boolean(set, 1);
                     break;
                 }
@@ -3605,6 +3605,7 @@
 xpath_derived_from(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
 {
     uint16_t i;
+    LY_ARRAY_SIZE_TYPE u;
     struct lyd_node_term *leaf;
     struct lysc_node_leaf *sleaf;
     struct lyd_value data = {0};
@@ -3656,8 +3657,8 @@
                 }
                 LY_CHECK_RET(rc);
 
-                LY_ARRAY_FOR(data.ident->derived, i) {
-                    if (data.ident->derived[i] == leaf->value.ident) {
+                LY_ARRAY_FOR(data.ident->derived, u) {
+                    if (data.ident->derived[u] == leaf->value.ident) {
                         set_fill_boolean(set, 1);
                         found = 1;
                         break;
@@ -3688,6 +3689,7 @@
 xpath_derived_from_or_self(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
 {
     uint16_t i;
+    LY_ARRAY_SIZE_TYPE u;
     struct lyd_node_term *leaf;
     struct lysc_node_leaf *sleaf;
     struct lyd_value data = {0};
@@ -3743,8 +3745,8 @@
                     set_fill_boolean(set, 1);
                     break;
                 }
-                LY_ARRAY_FOR(data.ident->derived, i) {
-                    if (data.ident->derived[i] == leaf->value.ident) {
+                LY_ARRAY_FOR(data.ident->derived, u) {
+                    if (data.ident->derived[u] == leaf->value.ident) {
                         set_fill_boolean(set, 1);
                         found = 1;
                         break;
diff --git a/tools/lint/commands.c b/tools/lint/commands.c
index 90c4ae8..0ef960e 100644
--- a/tools/lint/commands.c
+++ b/tools/lint/commands.c
@@ -1275,8 +1275,8 @@
     }
 
     if (!task) {
-        unsigned int len, max_len = 0;
-        unsigned int u;
+        size_t len, max_len = 0;
+        LY_ARRAY_SIZE_TYPE u;
         struct lysc_feature *features;
 
         printf("%s features:\n", module->name);
@@ -1296,7 +1296,7 @@
         }
 
         LY_ARRAY_FOR(features, u) {
-            printf("\t%-*s (%s)\n", max_len, features[u].name, (features[u].flags & LYS_FENABLED) ? "on" : "off");
+            printf("\t%-*s (%s)\n", (int)max_len, features[u].name, (features[u].flags & LYS_FENABLED) ? "on" : "off");
         }
         if (!u) {
             printf("\t(none)\n");
diff --git a/tools/lint/completion.c b/tools/lint/completion.c
index f2e8461..3a5394c 100644
--- a/tools/lint/completion.c
+++ b/tools/lint/completion.c
@@ -79,7 +79,7 @@
 static void
 get_model_completion(const char *hint, char ***matches, unsigned int *match_count)
 {
-    unsigned int u;
+    LY_ARRAY_SIZE_TYPE u;
     uint32_t idx = 0;
     const struct lys_module *module;
     void *p;