libyang REFACTOR use size-specific int types instead of generic types (#1177)

Align parameters' types with the values in (internal) structures.
diff --git a/compat/compat.c b/compat/compat.c
index 1ae54f6..0ed350a 100644
--- a/compat/compat.c
+++ b/compat/compat.c
@@ -128,7 +128,7 @@
 {
     static char line[256];
     char *ptr;
-    unsigned int len;
+    ssize_t len;
 
     if (!lineptr || !n) {
         errno = EINVAL;
diff --git a/src/common.c b/src/common.c
index 3a1f904..d473e3f 100644
--- a/src/common.c
+++ b/src/common.c
@@ -164,7 +164,7 @@
 }
 
 char *
-ly_strnchr(const char *s, int c, unsigned int len)
+ly_strnchr(const char *s, int c, size_t len)
 {
     for ( ; *s != (char)c; ++s, --len) {
         if ((*s == '\0') || (!len)) {
@@ -188,9 +188,8 @@
 LY_ERR
 ly_getutf8(const char **input, uint32_t *utf8_char, size_t *bytes_read)
 {
-    uint32_t c, len;
-    int aux;
-    int i;
+    uint32_t c, aux;
+    size_t len;
 
     if (bytes_read) {
         (*bytes_read) = 0;
@@ -224,7 +223,7 @@
         len = 3;
 
         c &= 0x0f;
-        for (i = 1; i <= 2; i++) {
+        for (uint64_t i = 1; i <= 2; i++) {
             aux = (*input)[i];
             if ((aux & 0xc0) != 0x80) {
                 return LY_EINVAL;
@@ -241,7 +240,7 @@
         len = 4;
 
         c &= 0x07;
-        for (i = 1; i <= 3; i++) {
+        for (uint64_t i = 1; i <= 3; i++) {
             aux = (*input)[i];
             if ((aux & 0xc0) != 0x80) {
                 return LY_EINVAL;
@@ -574,7 +573,7 @@
     LY_ERR ret = LY_EVALID;
     const char *in = *pred;
     size_t offset = 1;
-    int expr = 0;
+    uint8_t expr = 0;
     char quot;
 
     assert(in[0] == '\[');
diff --git a/src/common.h b/src/common.h
index a4110ba..e4c12b8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -67,8 +67,8 @@
 };
 
 extern THREAD_LOCAL enum int_log_opts log_opt;
-extern volatile uint8_t ly_log_level;
-extern volatile uint8_t ly_log_opts;
+extern volatile LY_LOG_LEVEL ly_log_level;
+extern volatile uint32_t ly_log_opts;
 
 /**
  * @brief Set error-app-tag to the last error record in the context.
@@ -105,7 +105,7 @@
 #ifdef NDEBUG
 #  define LOGDBG(dbg_group, str, ...)
 #else
-void ly_log_dbg(int group, const char *format, ...);
+void ly_log_dbg(uint32_t group, const char *format, ...);
 #  define LOGDBG(dbg_group, str, ...) ly_log_dbg(dbg_group, str, ##__VA_ARGS__);
 #endif
 
@@ -326,7 +326,7 @@
  * @param[in] len Limit the search to this number of characters in @p s.
  * @return Pointer to first @p c occurence in @p s, NULL if not found in first @p len characters.
  */
-char *ly_strnchr(const char *s, int c, unsigned int len);
+char *ly_strnchr(const char *s, int c, size_t len);
 
 /**
  * @brief Compare NULL-terminated @p refstr with @str_len bytes from @p str.
diff --git a/src/context.c b/src/context.c
index 59051d3..27b9822 100644
--- a/src/context.c
+++ b/src/context.c
@@ -70,7 +70,6 @@
 {
     struct stat st;
     char *new_dir = NULL;
-    unsigned int u;
 
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
 
@@ -92,7 +91,7 @@
                          LOGERR(ctx, LY_ESYS, "Given search directory \"%s\" is not a directory.", new_dir); free(new_dir),
                          LY_EINVAL);
         /* avoid path duplication */
-        for (u = 0; u < ctx->search_paths.count; ++u) {
+        for (uint32_t u = 0; u < ctx->search_paths.count; ++u) {
             if (!strcmp(new_dir, ctx->search_paths.objs[u])) {
                 free(new_dir);
                 return LY_EEXIST;
@@ -136,8 +135,6 @@
 API LY_ERR
 ly_ctx_unset_searchdir(struct ly_ctx *ctx, const char *value)
 {
-    unsigned int index;
-
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
 
     if (!ctx->search_paths.count) {
@@ -146,6 +143,8 @@
 
     if (value) {
         /* remove specific search directory */
+        uint32_t index;
+
         for (index = 0; index < ctx->search_paths.count; ++index) {
             if (!strcmp(value, ctx->search_paths.objs[index])) {
                 break;
@@ -167,7 +166,7 @@
 }
 
 API LY_ERR
-ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, unsigned int count)
+ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, uint32_t count)
 {
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
 
@@ -190,7 +189,7 @@
 }
 
 API LY_ERR
-ly_ctx_new(const char *search_dir, int options, struct ly_ctx **new_ctx)
+ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx)
 {
     struct ly_ctx *ctx = NULL;
     struct lys_module *module;
@@ -268,7 +267,7 @@
     return rc;
 }
 
-API int
+API uint16_t
 ly_ctx_get_options(const struct ly_ctx *ctx)
 {
     LY_CHECK_ARG_RET(ctx, ctx, 0);
@@ -276,7 +275,7 @@
 }
 
 API LY_ERR
-ly_ctx_set_options(struct ly_ctx *ctx, int option)
+ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option)
 {
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
     LY_CHECK_ERR_RET(option & LY_CTX_NOYANGLIBRARY, LOGARG(ctx, option), LY_EINVAL);
@@ -288,7 +287,7 @@
 }
 
 API LY_ERR
-ly_ctx_unset_options(struct ly_ctx *ctx, int option)
+ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option)
 {
     LY_CHECK_ARG_RET(ctx, ctx, LY_EINVAL);
     LY_CHECK_ERR_RET(option & LY_CTX_NOYANGLIBRARY, LOGARG(ctx, option), LY_EINVAL);
@@ -327,7 +326,7 @@
 }
 
 API const struct lys_module *
-ly_ctx_get_module_iter(const struct ly_ctx *ctx, unsigned int *index)
+ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *index)
 {
     LY_CHECK_ARG_RET(ctx, ctx, index, NULL);
 
@@ -352,7 +351,7 @@
  * @return Module matching the given key, NULL if no such module found.
  */
 static struct lys_module *
-ly_ctx_get_module_by_iter(const struct ly_ctx *ctx, const char *key, size_t key_size, size_t key_offset, unsigned int *index)
+ly_ctx_get_module_by_iter(const struct ly_ctx *ctx, const char *key, size_t key_size, size_t key_offset, uint32_t *index)
 {
     struct lys_module *mod;
     const char *value;
@@ -383,7 +382,7 @@
 ly_ctx_get_module_by(const struct ly_ctx *ctx, const char *key, size_t key_offset, const char *revision)
 {
     struct lys_module *mod;
-    unsigned int index = 0;
+    uint32_t index = 0;
 
     while ((mod = ly_ctx_get_module_by_iter(ctx, key, 0, key_offset, &index))) {
         if (!revision) {
@@ -427,7 +426,7 @@
 ly_ctx_get_module_latest_by(const struct ly_ctx *ctx, const char *key, size_t key_offset)
 {
     struct lys_module *mod;
-    unsigned int index = 0;
+    uint32_t index = 0;
 
     while ((mod = ly_ctx_get_module_by_iter(ctx, key, 0, key_offset, &index))) {
         if (mod->latest_revision) {
@@ -464,7 +463,7 @@
 ly_ctx_get_module_implemented_by(const struct ly_ctx *ctx, const char *key, size_t key_size, size_t key_offset)
 {
     struct lys_module *mod;
-    unsigned int index = 0;
+    uint32_t index = 0;
 
     while ((mod = ly_ctx_get_module_by_iter(ctx, key, key_size, key_offset, &index))) {
         if (mod->implemented) {
@@ -533,7 +532,7 @@
 }
 
 API const struct lysc_node *
-ly_ctx_get_node(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *data_path, int output)
+ly_ctx_get_node(const struct ly_ctx *ctx, const struct lysc_node *ctx_node, const char *data_path, uint8_t output)
 {
     const struct lysc_node *snode = NULL;
     struct lyxp_expr *exp = NULL;
@@ -622,7 +621,7 @@
 }
 
 static LY_ERR
-ylib_deviation(struct lyd_node *parent, const struct lys_module *cur_mod, int bis)
+ylib_deviation(struct lyd_node *parent, const struct lys_module *cur_mod, uint8_t bis)
 {
     LY_ARRAY_COUNT_TYPE i;
     struct lys_module *mod;
@@ -647,7 +646,7 @@
 }
 
 static LY_ERR
-ylib_submodules(struct lyd_node *parent, const struct lys_module *cur_mod, int bis)
+ylib_submodules(struct lyd_node *parent, const struct lys_module *cur_mod, uint8_t bis)
 {
     LY_ERR ret;
     LY_ARRAY_COUNT_TYPE i;
@@ -694,7 +693,8 @@
 {
     LY_ERR ret;
     uint32_t i;
-    int bis = 0, r;
+    uint8_t bis = 0;
+    int r;
     char id[8], *str;
     const struct lys_module *mod;
     struct lyd_node *root = NULL, *root_bis = NULL, *cont, *set_bis = NULL;
diff --git a/src/context.h b/src/context.h
index 7a14c9d..122ca8c 100644
--- a/src/context.h
+++ b/src/context.h
@@ -198,7 +198,7 @@
  * @param[out] new_ctx Pointer to the created libyang context if LY_SUCCESS returned.
  * @return LY_ERR return value.
  */
-LY_ERR ly_ctx_new(const char *search_dir, int options, struct ly_ctx **new_ctx);
+LY_ERR ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx);
 
 /**
  * @brief Add the search path into libyang context
@@ -234,7 +234,7 @@
  * Value 0 does not change the search path set.
  * @return LY_ERR return value
  */
-LY_ERR ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, unsigned int count);
+LY_ERR ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, uint32_t count);
 
 /**
  * @brief Get the NULL-terminated list of the search paths in libyang context. Do not modify the result!
@@ -251,7 +251,7 @@
  * @param[in] ctx Context to query.
  * @return Combination of all the currently set context's options, see @ref contextoptions.
  */
-int ly_ctx_get_options(const struct ly_ctx *ctx);
+uint16_t ly_ctx_get_options(const struct ly_ctx *ctx);
 
 /**
  * @brief Set some of the context's options, see @ref contextoptions.
@@ -259,7 +259,7 @@
  * @param[in] option Combination of the context's options to be set, see @ref contextoptions.
  * @return LY_ERR value.
  */
-LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, int option);
+LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option);
 
 /**
  * @brief Unset some of the context's options, see @ref contextoptions.
@@ -267,7 +267,7 @@
  * @param[in] option Combination of the context's options to be unset, see @ref contextoptions.
  * @return LY_ERR value.
  */
-LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, int option);
+LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option);
 
 /**
  * @brief Get current ID of the modules set. The value is available also
@@ -373,7 +373,7 @@
  * to be used in all calls starting with value 0.
  * @return Next context module, NULL if the last was already returned.
  */
-const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, unsigned int *index);
+const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *index);
 
 /**
  * @brief Get YANG module of the given namespace and revision.
@@ -418,7 +418,7 @@
  * @return Found schema node or NULL.
  */
 const struct lysc_node *ly_ctx_get_node(const struct ly_ctx *ctx, const struct lysc_node *ctx_node,
-        const char *data_path, int output);
+        const char *data_path, uint8_t output);
 
 /**
  * @brief Reset cached latest revision information of the schemas in the context.
diff --git a/src/diff.c b/src/diff.c
index e20c520..a02c5dd 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -231,7 +231,7 @@
  * @return LY_ERR value on other errors.
  */
 static LY_ERR
-lyd_diff_userord_attrs(const struct lyd_node *first, const struct lyd_node *second, int options,
+lyd_diff_userord_attrs(const struct lyd_node *first, const struct lyd_node *second, uint16_t options,
         struct lyd_diff_userord **userord, enum lyd_diff_op *op, const char **orig_default, char **value,
         char **orig_value, char **key, char **orig_key)
 {
@@ -394,7 +394,7 @@
  * @return LY_ERR value on other errors.
  */
 static LY_ERR
-lyd_diff_attrs(const struct lyd_node *first, const struct lyd_node *second, int options, enum lyd_diff_op *op,
+lyd_diff_attrs(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, enum lyd_diff_op *op,
         const char **orig_default, char **orig_value)
 {
     const struct lysc_node *schema;
@@ -516,7 +516,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second, int options, int nosiblings,
+lyd_diff_siblings_r(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, uint8_t nosiblings,
         struct lyd_node **diff)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -669,7 +669,7 @@
 }
 
 static LY_ERR
-lyd_diff(const struct lyd_node *first, const struct lyd_node *second, int options, int nosiblings, struct lyd_node **diff)
+lyd_diff(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, uint8_t nosiblings, struct lyd_node **diff)
 {
     const struct ly_ctx *ctx;
 
@@ -694,13 +694,13 @@
 }
 
 API LY_ERR
-lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff)
 {
     return lyd_diff(first, second, options, 1, diff);
 }
 
 API LY_ERR
-lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff)
+lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff)
 {
     return lyd_diff(first, second, options, 0, diff);
 }
@@ -1512,7 +1512,7 @@
     struct lyd_meta *meta;
     const char *val1 = NULL;
     char *val2;
-    int flags;
+    uint32_t flags;
 
     meta = lyd_find_meta(leaf->meta, mod, "orig-value");
     LY_CHECK_ERR_RET(!meta, LOGINT(LYD_CTX(leaf)), LY_EINT);
@@ -1538,7 +1538,7 @@
 lyd_diff_reverse_default(struct lyd_node *node, const struct lys_module *mod)
 {
     struct lyd_meta *meta;
-    int flag1, flag2;
+    uint32_t flag1, flag2;
 
     meta = lyd_find_meta(node->meta, mod, "orig-default");
     if (!meta) {
diff --git a/src/hash_table.c b/src/hash_table.c
index 3c749ea..bc6ec8b 100644
--- a/src/hash_table.c
+++ b/src/hash_table.c
@@ -24,8 +24,8 @@
 #include "common.h"
 #include "dict.h"
 
-static int
-lydict_val_eq(void *val1_p, void *val2_p, int UNUSED(mod), void *cb_data)
+static uint8_t
+lydict_val_eq(void *val1_p, void *val2_p, uint8_t UNUSED(mod), void *cb_data)
 {
     LY_CHECK_ARG_RET(NULL, val1_p, val2_p, cb_data, 0);
 
@@ -55,13 +55,12 @@
 void
 lydict_clean(struct dict_table *dict)
 {
-    unsigned int i;
     struct dict_rec *dict_rec = NULL;
     struct ht_rec *rec = NULL;
 
     LY_CHECK_ARG_RET(NULL, dict, );
 
-    for (i = 0; i < dict->hash_tab->size; i++) {
+    for (uint32_t i = 0; i < dict->hash_tab->size; i++) {
         /* get ith record */
         rec = (struct ht_rec *)&dict->hash_tab->recs[i * dict->hash_tab->rec_size];
         if (rec->hits == 1) {
@@ -128,8 +127,8 @@
 API void
 lydict_remove(const struct ly_ctx *ctx, const char *value)
 {
+    LY_ERR ret;
     size_t len;
-    int ret;
     uint32_t hash;
     struct dict_rec rec, *match = NULL;
     char *val_p;
@@ -151,7 +150,7 @@
     /* check if value is already inserted */
     ret = lyht_find(ctx->dict.hash_tab, &rec, hash, (void **)&match);
 
-    if (ret == 0) {
+    if (ret == LY_SUCCESS) {
         LY_CHECK_ERR_GOTO(!match, LOGINT(ctx), finish);
 
         /* if value is already in dictionary, decrement reference counter */
@@ -174,10 +173,10 @@
 }
 
 static char *
-dict_insert(const struct ly_ctx *ctx, char *value, size_t len, int zerocopy)
+dict_insert(const struct ly_ctx *ctx, char *value, size_t len, uint8_t zerocopy)
 {
+    LY_ERR ret = 0;
     struct dict_rec *match = NULL, rec;
-    int ret = 0;
     uint32_t hash;
 
     hash = dict_hash(value, len);
@@ -256,7 +255,7 @@
 }
 
 struct hash_table *
-lyht_new(uint32_t size, uint16_t val_size, values_equal_cb val_equal, void *cb_data, int resize)
+lyht_new(uint32_t size, uint16_t val_size, values_equal_cb val_equal, void *cb_data, uint16_t resize)
 {
     struct hash_table *ht;
 
@@ -276,7 +275,7 @@
     ht->size = size;
     ht->val_equal = val_equal;
     ht->cb_data = cb_data;
-    ht->resize = (uint16_t)resize;
+    ht->resize = resize;
 
     ht->rec_size = (sizeof(struct ht_rec) - 1) + val_size;
     /* allocate the records correctly */
@@ -333,12 +332,11 @@
 }
 
 static LY_ERR
-lyht_resize(struct hash_table *ht, int enlarge)
+lyht_resize(struct hash_table *ht, uint8_t enlarge)
 {
     struct ht_rec *rec;
     unsigned char *old_recs;
     uint32_t i, old_size;
-    int ret;
 
     old_recs = ht->recs;
     old_size = ht->size;
@@ -361,7 +359,7 @@
     for (i = 0; i < old_size; ++i) {
         rec = lyht_get_rec(old_recs, ht->rec_size, i);
         if (rec->hits > 0) {
-            ret = lyht_insert(ht, rec->val, rec->hash, NULL);
+            LY_ERR ret = lyht_insert(ht, rec->val, rec->hash, NULL);
             assert(!ret);
             (void)ret;
         }
@@ -487,7 +485,7 @@
  * @return LY_SUCCESS if record was found.
  */
 static LY_ERR
-lyht_find_rec(struct hash_table *ht, void *val_p, uint32_t hash, int mod, struct ht_rec **crec_p, uint32_t *col,
+lyht_find_rec(struct hash_table *ht, void *val_p, uint32_t hash, uint8_t mod, struct ht_rec **crec_p, uint32_t *col,
         struct ht_rec **rec_p)
 {
     struct ht_rec *rec, *crec;
@@ -593,9 +591,9 @@
 lyht_insert_with_resize_cb(struct hash_table *ht, void *val_p, uint32_t hash,
         values_equal_cb resize_val_equal, void **match_p)
 {
+    LY_ERR r, ret = LY_SUCCESS;
     struct ht_rec *rec, *crec = NULL;
     int32_t i;
-    int r, ret;
     values_equal_cb old_val_equal;
 
     if (!lyht_find_first(ht, hash, &rec)) {
@@ -646,7 +644,6 @@
     }
 
     /* check size & enlarge if needed */
-    ret = LY_SUCCESS;
     ++ht->used;
     if (ht->resize) {
         r = (ht->used * 100) / ht->size;
@@ -685,7 +682,8 @@
 {
     struct ht_rec *rec, *crec;
     int32_t i;
-    int first_matched = 0, r, ret;
+    uint8_t first_matched = 0;
+    LY_ERR r, ret = LY_SUCCESS;
 
     LY_CHECK_ERR_RET(lyht_find_first(ht, hash, &rec), LOGARG(NULL, hash), LY_ENOTFOUND); /* hash not found */
 
@@ -725,7 +723,6 @@
     }
 
     /* check size & shrink if needed */
-    ret = LY_SUCCESS;
     --ht->used;
     if (ht->resize == 2) {
         r = (ht->used * 100) / ht->size;
diff --git a/src/hash_table.h b/src/hash_table.h
index dde9570..6c44d6c 100644
--- a/src/hash_table.h
+++ b/src/hash_table.h
@@ -47,7 +47,7 @@
  * @param[in] cb_data User callback data.
  * @return 0 on non-equal, non-zero on equal.
  */
-typedef int (*values_equal_cb)(void *val1_p, void *val2_p, int mod, void *cb_data);
+typedef uint8_t (*values_equal_cb)(void *val1_p, void *val2_p, uint8_t mod, void *cb_data);
 
 /** when the table is at least this much percent full, it is enlarged (double the size) */
 #define LYHT_ENLARGE_PERCENTAGE 75
@@ -128,7 +128,7 @@
  * @param[in] resize Whether to resize the table on too few/too many records taken.
  * @return Empty hash table, NULL on error.
  */
-struct hash_table *lyht_new(uint32_t size, uint16_t val_size, values_equal_cb val_equal, void *cb_data, int resize);
+struct hash_table *lyht_new(uint32_t size, uint16_t val_size, values_equal_cb val_equal, void *cb_data, uint16_t resize);
 
 /**
  * @brief Set hash table value equal callback.
diff --git a/src/json.c b/src/json.c
index 2cd60dd..65de12b 100644
--- a/src/json.c
+++ b/src/json.c
@@ -87,7 +87,7 @@
  * @brief Set value corresponding to the current context's status
  */
 static void
-lyjson_ctx_set_value(struct lyjson_ctx *jsonctx, const char *value, size_t value_len, int dynamic)
+lyjson_ctx_set_value(struct lyjson_ctx *jsonctx, const char *value, size_t value_len, uint8_t dynamic)
 {
     assert(jsonctx);
 
@@ -323,7 +323,7 @@
 {
     size_t offset = 0, exponent = 0;
     const char *in = jsonctx->in->current;
-    int minus = 0;
+    uint8_t minus = 0;
 
     if (in[offset] == '-') {
         ++offset;
@@ -376,7 +376,7 @@
         char *ptr, *dec_point, *num;
         const char *e_ptr = &in[exponent + 1];
         size_t num_len, i;
-        long int dp_position; /* final position of the deciaml point */
+        int64_t dp_position; /* final position of the deciaml point */
 
         errno = 0;
         e_val = strtol(e_ptr, &ptr, 10);
@@ -437,7 +437,9 @@
             }
         }
         /* copy the value */
-        for (unsigned int dp_placed = dp_position ? 0 : 1, j = minus; j < exponent; j++) {
+        uint8_t dp_placed;
+        size_t j;
+        for (dp_placed = dp_position ? 0 : 1, j = minus; j < exponent; j++) {
             if (in[j] == '.') {
                 continue;
             }
@@ -679,7 +681,7 @@
 lyjson_ctx_next(struct lyjson_ctx *jsonctx, enum LYJSON_PARSER_STATUS *status)
 {
     LY_ERR ret = LY_SUCCESS;
-    int toplevel = 0;
+    uint8_t toplevel = 0;
     enum LYJSON_PARSER_STATUS prev;
 
     assert(jsonctx);
diff --git a/src/json.h b/src/json.h
index d53f673..8948969 100644
--- a/src/json.h
+++ b/src/json.h
@@ -60,14 +60,14 @@
 
     const char *value;      /* LYJSON_STRING, LYJSON_NUMBER, LYJSON_OBJECT */
     size_t value_len;       /* LYJSON_STRING, LYJSON_NUMBER, LYJSON_OBJECT */
-    int dynamic;            /* LYJSON_STRING, LYJSON_NUMBER, LYJSON_OBJECT */
+    uint8_t dynamic;        /* LYJSON_STRING, LYJSON_NUMBER, LYJSON_OBJECT */
 
     struct {
         enum LYJSON_PARSER_STATUS status;
         uint32_t status_count;
         const char *value;
         size_t value_len;
-        int dynamic;
+        uint8_t dynamic;
         const char *input;
     } backup;
 };
diff --git a/src/log.c b/src/log.c
index 1b4e229..53a5726 100644
--- a/src/log.c
+++ b/src/log.c
@@ -31,12 +31,12 @@
 #include "tree_data.h"
 #include "tree_schema.h"
 
-volatile uint8_t ly_log_level = LY_LLWRN;
-volatile uint8_t ly_log_opts = LY_LOLOG | LY_LOSTORE_LAST;
+volatile LY_LOG_LEVEL ly_log_level = LY_LLWRN;
+volatile uint32_t ly_log_opts = LY_LOLOG | LY_LOSTORE_LAST;
 static ly_log_clb log_clb;
-static volatile int path_flag = 1;
+static volatile uint8_t path_flag = 1;
 #ifndef NDEBUG
-volatile int ly_log_dbg_groups = 0;
+volatile uint32_t ly_log_dbg_groups = 0;
 #endif
 
 /* how many bytes add when enlarging buffers */
@@ -190,17 +190,17 @@
     return prev;
 }
 
-API int
-ly_log_options(int opts)
+API uint32_t
+ly_log_options(uint32_t opts)
 {
-    uint8_t prev = ly_log_opts;
+    uint32_t prev = ly_log_opts;
 
     ly_log_opts = opts;
     return prev;
 }
 
 API void
-ly_verb_dbg(int dbg_groups)
+ly_verb_dbg(uint32_t dbg_groups)
 {
 #ifndef NDEBUG
     ly_log_dbg_groups = dbg_groups;
@@ -210,7 +210,7 @@
 }
 
 API void
-ly_set_log_clb(ly_log_clb clb, int path)
+ly_set_log_clb(ly_log_clb clb, uint8_t path)
 {
     log_clb = clb;
     path_flag = path;
@@ -294,7 +294,7 @@
         const char *format, va_list args)
 {
     char *msg = NULL;
-    int free_strs;
+    uint8_t free_strs;
 
     if (level > ly_log_level) {
         /* do not print or store the message */
@@ -349,7 +349,7 @@
 #ifndef NDEBUG
 
 void
-ly_log_dbg(int group, const char *format, ...)
+ly_log_dbg(uint32_t group, const char *format, ...)
 {
     char *dbg_format;
     const char *str_group;
diff --git a/src/log.h b/src/log.h
index 87bab61..00eb55c 100644
--- a/src/log.h
+++ b/src/log.h
@@ -15,6 +15,8 @@
 #ifndef LY_LOG_H_
 #define LY_LOG_H_
 
+#include <stdint.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -75,7 +77,7 @@
  * @param[in] opts Bitfield of @ref logopts.
  * @return Previous logger options.
  */
-int ly_log_options(int opts);
+uint32_t ly_log_options(uint32_t opts);
 
 #ifndef NDEBUG
 
@@ -102,7 +104,7 @@
  * @brief Enable specific debugging messages (independent of log level).
  * @param[in] dbg_groups Bitfield of enabled debug message groups (see @ref dbggroup).
  */
-void ly_verb_dbg(int dbg_groups);
+void ly_verb_dbg(uint32_t dbg_groups);
 
 #endif
 
@@ -129,7 +131,7 @@
  *            presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
  *            not bother with resolving the path.
  */
-void ly_set_log_clb(ly_log_clb clb, int path);
+void ly_set_log_clb(ly_log_clb clb, uint8_t path);
 
 /**
  * @brief Get logger callback.
diff --git a/src/parser.c b/src/parser.c
index ffbe1d9..f1fd349 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -288,7 +288,7 @@
 }
 
 API void
-ly_in_free(struct ly_in *in, int destroy)
+ly_in_free(struct ly_in *in, uint8_t destroy)
 {
     if (!in) {
         return;
@@ -407,7 +407,7 @@
 
 LY_ERR
 lyd_parser_create_term(struct lyd_ctx *lydctx, const struct lysc_node *schema, const char *value, size_t value_len,
-        int *dynamic, int value_hints, LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node)
+        uint8_t *dynamic, uint32_t value_hints, LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node)
 {
     LY_ERR ret;
 
@@ -423,7 +423,7 @@
 
 LY_ERR
 lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod,
-        const char *name, size_t name_len, const char *value, size_t value_len, int *dynamic, int value_hints,
+        const char *name, size_t name_len, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hints,
         LY_PREFIX_FORMAT format, void *prefix_data, const struct lysc_node *ctx_snode)
 {
     LY_ERR ret;
diff --git a/src/parser.h b/src/parser.h
index 28c40bd..2c35f24 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -167,7 +167,7 @@
  * @param[in] destroy Flag to free the input data buffer (for LY_IN_MEMORY) or to
  * close stream/file descriptor (for LY_IN_FD and LY_IN_FILE)
  */
-void ly_in_free(struct ly_in *in, int destroy);
+void ly_in_free(struct ly_in *in, uint8_t destroy);
 
 #ifdef __cplusplus
 }
diff --git a/src/parser_data.h b/src/parser_data.h
index 000f25f..4b16efc 100644
--- a/src/parser_data.h
+++ b/src/parser_data.h
@@ -129,8 +129,8 @@
  * @return LY_SUCCESS in case of successful parsing (and validation).
  * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
  */
-LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, int parse_options,
-        int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, uint32_t parse_options,
+        uint32_t validate_options, struct lyd_node **tree);
 
 /**
  * @brief Parse (and validate) input data as a YANG data tree.
@@ -147,8 +147,8 @@
  * @return LY_SUCCESS in case of successful parsing (and validation).
  * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
  */
-LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int parse_options,
-        int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options,
+        uint32_t validate_options, struct lyd_node **tree);
 
 /**
  * @brief Parse (and validate) input data as a YANG data tree.
@@ -165,7 +165,7 @@
  * @return LY_SUCCESS in case of successful parsing (and validation).
  * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
  */
-LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, int parse_options, int validate_options,
+LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree);
 
 /**
@@ -183,8 +183,8 @@
  * @return LY_SUCCESS in case of successful parsing (and validation).
  * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
  */
-LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int parse_options,
-        int validate_options, struct lyd_node **tree);
+LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options,
+        uint32_t validate_options, struct lyd_node **tree);
 
 /**
  * @brief Parse (and validate) data from the input handler as a YANG RPC/action invocation.
@@ -256,7 +256,7 @@
  * @return LY_SUCCESS on success.
  * @return LY_ERR error on error.
  */
-LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff);
+LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, struct lyd_node **diff);
 
 /**
  * @brief Fully validate a data tree of a module.
@@ -268,7 +268,7 @@
  * @return LY_SUCCESS on success.
  * @return LY_ERR error on error.
  */
-LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, int val_opts, struct lyd_node **diff);
+LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, struct lyd_node **diff);
 
 /**
  * @brief Validate an RPC/action, notification, or RPC/action reply.
diff --git a/src/parser_internal.h b/src/parser_internal.h
index d547913..03199f8 100644
--- a/src/parser_internal.h
+++ b/src/parser_internal.h
@@ -171,7 +171,7 @@
  * @param[in] value_hints Data parser's hint for the value's type.
  */
 LY_ERR lyd_parser_create_term(struct lyd_ctx *lydctx, const struct lysc_node *schema, const char *value, size_t value_len,
-        int *dynamic, int value_hints, LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node);
+        uint8_t *dynamic, uint32_t value_hints, LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node);
 
 /**
  * @brief Wrapper around lyd_create_meta() for data parsers.
@@ -181,7 +181,7 @@
  */
 LY_ERR lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct lyd_meta **meta,
         const struct lys_module *mod, const char *name, size_t name_len, const char *value,
-        size_t value_len, int *dynamic, int value_hints, LY_PREFIX_FORMAT format,
+        size_t value_len, uint8_t *dynamic, uint32_t value_hints, LY_PREFIX_FORMAT format,
         void *prefix_data, const struct lysc_node *ctx_snode);
 
 #endif /* LY_PARSER_INTERNAL_H_ */
diff --git a/src/parser_json.c b/src/parser_json.c
index a2bdbfb..5585aac 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -86,11 +86,11 @@
  */
 static void
 lydjson_parse_name(const char *value, size_t value_len, const char **name_p, size_t *name_len_p, const char **prefix_p,
-        size_t *prefix_len_p, int *is_meta_p)
+        size_t *prefix_len_p, uint8_t *is_meta_p)
 {
     const char *name, *prefix = NULL;
     size_t name_len, prefix_len = 0;
-    int is_meta = 0;
+    uint8_t is_meta = 0;
 
     name = memchr(value, ':', value_len);
     if (name != NULL) {
@@ -183,13 +183,13 @@
  * @return LY_ENOT in case the input data are expected to be skipped
  */
 static LY_ERR
-lydjson_get_snode(const struct lyd_json_ctx *lydctx, int is_attr, const char *prefix, size_t prefix_len, const char *name,
+lydjson_get_snode(const struct lyd_json_ctx *lydctx, uint8_t is_attr, const char *prefix, size_t prefix_len, const char *name,
         size_t name_len, const struct lyd_node_inner *parent, const struct lysc_node **snode_p)
 {
     struct lys_module *mod = NULL;
 
     /* leave if-feature check for validation */
-    int getnext_opts = LYS_GETNEXT_NOSTATECHECK | (lydctx->int_opts & LYD_INTOPT_REPLY ? LYS_GETNEXT_OUTPUT : 0);
+    uint32_t getnext_opts = LYS_GETNEXT_NOSTATECHECK | (lydctx->int_opts & LYD_INTOPT_REPLY ? LYS_GETNEXT_OUTPUT : 0);
 
     /* init return value */
     *snode_p = NULL;
@@ -371,7 +371,7 @@
         while (key_set.count && status != LYJSON_OBJECT_CLOSED) {
             const char *name, *prefix;
             size_t name_len, prefix_len;
-            int is_attr;
+            uint8_t is_attr;
 
             /* match the key */
             snode = NULL;
@@ -436,7 +436,7 @@
  * @return LY_EINVAL in case of invalid context status not referring to a value.
  */
 static LY_ERR
-lydjson_value_type_hint(struct lyd_json_ctx *lydctx, enum LYJSON_PARSER_STATUS *status_p, int *type_hint_p)
+lydjson_value_type_hint(struct lyd_json_ctx *lydctx, enum LYJSON_PARSER_STATUS *status_p, uint32_t *type_hint_p)
 {
     *type_hint_p = 0;
 
@@ -480,7 +480,7 @@
  * and they are expected to be parsed as opaq nodes.
  */
 static LY_ERR
-lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, int *type_hint_p)
+lydjson_data_check_opaq(struct lyd_json_ctx *lydctx, const struct lysc_node *snode, uint32_t *type_hint_p)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyjson_ctx *jsonctx = lydctx->jsonctx;
@@ -548,14 +548,14 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_node *node, *attr, *next, *start = *first_p, *meta_iter;
-    unsigned int instance = 0;
+    uint64_t instance = 0;
     const char *prev = NULL;
 
     /* finish linking metadata */
     LY_LIST_FOR_SAFE(*first_p, next, attr) {
         struct lyd_node_opaq *meta_container = (struct lyd_node_opaq *)attr;
-        unsigned int match = 0;
-        int is_attr;
+        uint64_t match = 0;
+        uint8_t is_attr;
         const char *name, *prefix;
         size_t name_len, prefix_len;
         const struct lysc_node *snode;
@@ -599,7 +599,7 @@
                     /* convert opaq node to a attribute of the opaq node */
                     struct lyd_node_opaq *meta = (struct lyd_node_opaq *)meta_iter;
                     struct ly_prefix *val_prefs = NULL;
-                    int dynamic = 0;
+                    uint8_t dynamic = 0;
 
                     /* get value prefixes */
                     LY_CHECK_GOTO(ret = lydjson_get_value_prefixes(lydctx->jsonctx->ctx, lydctx->jsonctx->value, lydctx->jsonctx->value_len, &val_prefs), cleanup);
@@ -634,7 +634,7 @@
                     /* convert opaq node to a metadata of the node */
                     struct lyd_node_opaq *meta = (struct lyd_node_opaq *)meta_iter;
                     struct lys_module *mod = NULL;
-                    int dynamic = 0;
+                    uint8_t dynamic = 0;
 
                     mod = ly_ctx_get_module_implemented(lydctx->jsonctx->ctx, meta->prefix.id);
                     if (mod) {
@@ -701,15 +701,15 @@
     LY_ERR ret = LY_SUCCESS;
     enum LYJSON_PARSER_STATUS status;
     const char *expected;
-    int in_parent = 0;
+    uint8_t in_parent = 0;
     const char *name, *prefix = NULL;
     size_t name_len, prefix_len = 0;
     struct lys_module *mod;
     struct lyd_meta *meta = NULL;
     const struct ly_ctx *ctx = lydctx->jsonctx->ctx;
-    int is_attr = 0;
+    uint8_t is_attr = 0;
     struct lyd_node *prev = node;
-    int instance = 0;
+    uint32_t instance = 0;
     uint16_t nodetype;
 
     assert(snode || node);
@@ -743,7 +743,7 @@
 
         if (!node || node->schema != prev->schema) {
             LOGVAL(lydctx->jsonctx->ctx, LY_VLOG_LYD, prev->parent, LYVE_REFERENCE,
-                   "Missing JSON data instance no. %d of %s:%s to be coupled with metadata.",
+                   "Missing JSON data instance no. %u of %s:%s to be coupled with metadata.",
                    instance, prev->schema->module->name, prev->schema->name);
             ret = LY_EVALID;
             goto cleanup;
@@ -928,8 +928,8 @@
     const char *value = NULL, *module_name;
     size_t value_len = 0, module_name_len = 0;
     struct ly_prefix *val_prefs = NULL;
-    int dynamic = 0;
-    int type_hint = 0;
+    uint8_t dynamic = 0;
+    uint32_t type_hint = 0;
 
     if (*status_inner_p != LYJSON_OBJECT && *status_inner_p != LYJSON_OBJECT_EMPTY) {
         /* prepare for creating opaq node with a value */
@@ -1086,7 +1086,7 @@
         enum LYJSON_PARSER_STATUS *status, struct lyd_node **node)
 {
     LY_ERR ret;
-    int type_hint;
+    uint32_t type_hint;
     uint32_t prev_opts;
     struct lyd_node *tree = NULL;
 
@@ -1199,7 +1199,7 @@
     enum LYJSON_PARSER_STATUS status_inner = 0;
     const char *name, *prefix = NULL;
     size_t name_len, prefix_len = 0;
-    int is_meta = 0;
+    uint8_t is_meta = 0;
     const struct lysc_node *snode = NULL;
     struct lyd_node *node = NULL, *attr_node = NULL;
     const struct ly_ctx *ctx = lydctx->jsonctx->ctx;
@@ -1368,7 +1368,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyd_parse_json_init(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+lyd_parse_json_init(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_json_ctx **lydctx_p)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -1405,7 +1405,7 @@
 }
 
 LY_ERR
-lyd_parse_json_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+lyd_parse_json_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -1464,7 +1464,7 @@
     LY_ERR ret = LY_ENOT, r;
     const char *name, *prefix, *value = NULL;
     size_t name_len, prefix_len, value_len;
-    int is_attr, dynamic = 0;
+    uint8_t is_attr, dynamic = 0;
     enum LYJSON_PARSER_STATUS status;
     struct lyd_node *et;
 
@@ -1631,7 +1631,7 @@
     LY_ERR ret = LY_ENOT, r;
     const char *name, *prefix;
     size_t name_len, prefix_len;
-    int is_attr;
+    uint8_t is_attr;
     enum LYJSON_PARSER_STATUS status;
 
     *envp_p = NULL;
diff --git a/src/parser_lyb.c b/src/parser_lyb.c
index ce04658..e084458 100644
--- a/src/parser_lyb.c
+++ b/src/parser_lyb.c
@@ -171,9 +171,9 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyb_read_string(char **str, int with_length, struct lylyb_ctx *lybctx)
+lyb_read_string(char **str, uint8_t with_length, struct lylyb_ctx *lybctx)
 {
-    int next_chunk = 0;
+    uint8_t next_chunk = 0;
     size_t len = 0, cur_len;
 
     *str = NULL;
@@ -345,7 +345,7 @@
 lyb_parse_metadata(struct lyd_lyb_ctx *lybctx, const struct lysc_node *sparent, struct lyd_meta **meta)
 {
     LY_ERR ret = LY_SUCCESS;
-    int dynamic;
+    uint8_t dynamic;
     uint8_t i, count = 0;
     char *meta_name = NULL, *meta_value;
     const struct lys_module *mod;
@@ -464,7 +464,7 @@
     uint8_t count, i;
     struct lyd_attr *attr2;
     char *prefix = NULL, *module_name = NULL, *name = NULL, *value = NULL;
-    int dynamic = 0;
+    uint8_t dynamic = 0;
     LYD_FORMAT format = 0;
     struct ly_prefix *val_prefs = NULL;
 
@@ -589,7 +589,7 @@
     uint8_t i, j;
     const struct lysc_node *sibling;
     LYB_HASH hash[LYB_HASH_BITS - 1];
-    int getnext_opts;
+    uint32_t getnext_opts;
 
     *snode = NULL;
     /* leave if-feature check for validation */
@@ -688,9 +688,9 @@
     struct ly_prefix *val_prefs = NULL;
     LYD_ANYDATA_VALUETYPE value_type;
     char *value = NULL, *name = NULL, *prefix = NULL, *module_key = NULL;
-    int dynamic = 0;
+    uint8_t dynamic = 0;
     LYD_FORMAT format = 0;
-    int prev_lo;
+    uint32_t prev_lo;
     const struct ly_ctx *ctx = lybctx->lybctx->ctx;
 
     /* register a new subtree */
@@ -986,8 +986,8 @@
  * @param[out] lydctx_p Data parser context to finish validation.
  */
 static LY_ERR
-lyd_parse_lyb_(const struct ly_ctx *ctx, struct lyd_node_inner **parent, struct ly_in *in, int parse_options, int validate_options,
-        int data_type, struct lyd_node **tree_p, struct lyd_node **op_p, struct lyd_ctx **lydctx_p)
+lyd_parse_lyb_(const struct ly_ctx *ctx, struct lyd_node_inner **parent, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
+        uint32_t data_type, struct lyd_node **tree_p, struct lyd_node **op_p, struct lyd_ctx **lydctx_p)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_lyb_ctx *lybctx;
@@ -1083,7 +1083,7 @@
 }
 
 LY_ERR
-lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p)
 {
     return lyd_parse_lyb_(ctx, NULL, in, parse_options, validate_options, 0, tree_p, NULL, lydctx_p);
diff --git a/src/parser_schema.h b/src/parser_schema.h
index 5001fe8..6be8f6f 100644
--- a/src/parser_schema.h
+++ b/src/parser_schema.h
@@ -107,7 +107,7 @@
  * file suffix.
  * @return LY_ERR value (LY_SUCCESS is returned even if the file is not found, then the *localfile is NULL).
  */
-LY_ERR lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision,
+LY_ERR lys_search_localfile(const char * const *searchpaths, uint8_t cwd, const char *name, const char *revision,
         char **localfile, LYS_INFORMAT *format);
 
 /** @} schematree */
diff --git a/src/parser_stmt.c b/src/parser_stmt.c
index c9b5809..af0feee 100644
--- a/src/parser_stmt.c
+++ b/src/parser_stmt.c
@@ -32,8 +32,8 @@
 static LY_ERR
 lysp_stmt_validate_value(struct lys_parser_ctx *ctx, enum yang_arg val_type, const char *val)
 {
-    int prefix = 0, first = 1;
-    unsigned int c;
+    uint8_t prefix = 0, first = 1;
+    uint32_t c;
     size_t utf8_char_len;
 
     while (*val) {
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 7e2647a..491b21c 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -381,7 +381,7 @@
     uint32_t prev_opts;
     struct lyd_node *node = NULL, *anchor;
     struct ly_prefix *val_prefs;
-    int getnext_opts;
+    uint32_t getnext_opts;
 
     xmlctx = lydctx->xmlctx;
     ctx = xmlctx->ctx;
@@ -616,7 +616,7 @@
 }
 
 LY_ERR
-lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p)
 {
     LY_ERR ret = LY_SUCCESS;
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 88cd2b1..3a18537 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -139,9 +139,9 @@
  */
 LY_ERR
 buf_store_char(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p, size_t *word_len,
-        char **word_b, size_t *buf_len, int need_buf, int *prefix)
+        char **word_b, size_t *buf_len, uint8_t need_buf, uint8_t *prefix)
 {
-    unsigned int c;
+    uint32_t c;
     size_t len;
 
     /* check  valid combination of input paremeters - if need_buf specified, word_b must be provided */
@@ -220,7 +220,7 @@
  * @return LY_ERR values.
  */
 LY_ERR
-skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, int comment)
+skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t comment)
 {
     /* internal statuses: 0 - comment ended,
      *                    1 - in line comment,
@@ -295,10 +295,11 @@
     /* string: 0 - string ended, 1 - string with ', 2 - string with ", 3 - string with " with last character \,
      *         4 - string finished, now skipping whitespaces looking for +,
      *         5 - string continues after +, skipping whitespaces */
-    unsigned int string, block_indent = 0, current_indent = 0, need_buf = 0;
+    uint8_t string;
+    uint64_t block_indent = 0, current_indent = 0;
+    uint8_t need_buf = 0, prefix = 0;
     const char *c;
-    int prefix = 0;
-    unsigned int trailing_ws = 0; /* current number of stored trailing whitespace characters */
+    uint64_t trailing_ws = 0; /* current number of stored trailing whitespace characters */
 
     if (in->current[0] == '\"') {
         string = 2;
@@ -514,7 +515,7 @@
         char **word_b, size_t *word_len)
 {
     size_t buf_len = 0;
-    int prefix = 0;
+    uint8_t prefix = 0;
     /* word buffer - dynamically allocated */
     *word_b = NULL;
 
@@ -631,9 +632,8 @@
 LY_ERR
 get_keyword(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt *kw, char **word_p, size_t *word_len)
 {
-    int prefix;
+    uint8_t prefix;
     const char *word_start;
-    unsigned int c;
     size_t len;
 
     if (word_p) {
@@ -721,6 +721,8 @@
 extension:
         while (in->current[0] && (in->current[0] != ' ') && (in->current[0] != '\t') && (in->current[0] != '\n')
                 && (in->current[0] != '{') && (in->current[0] != ';')) {
+            uint32_t c = 0;
+
             LY_CHECK_ERR_RET(ly_getutf8(&in->current, &c, &len),
                              LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, in->current[-len]), LY_EVALID);
             ++ctx->indent;
@@ -816,7 +818,7 @@
  * @return LY_ERR values.
  */
 static LY_ERR
-parse_ext(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char *ext_name, int ext_name_len, LYEXT_SUBSTMT insubstmt,
+parse_ext(struct lys_yang_parser_ctx *ctx, struct ly_in *in, const char *ext_name, size_t ext_name_len, LYEXT_SUBSTMT insubstmt,
         LY_ARRAY_COUNT_TYPE insubstmt_index, struct lysp_ext_instance **exts)
 {
     LY_ERR ret = LY_SUCCESS;
diff --git a/src/parser_yin.c b/src/parser_yin.c
index c907f97..442c038 100644
--- a/src/parser_yin.c
+++ b/src/parser_yin.c
@@ -276,8 +276,8 @@
 LY_ERR
 yin_validate_value(struct lys_yin_parser_ctx *ctx, enum yang_arg val_type)
 {
-    int prefix = 0;
-    unsigned int c;
+    uint8_t prefix = 0;
+    uint32_t c;
     size_t utf8_char_len, already_read = 0;
     const char *val;
 
@@ -292,10 +292,10 @@
 
         switch (val_type) {
         case Y_IDENTIF_ARG:
-            LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, !already_read, NULL));
+            LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, already_read ? 0 : 1, NULL));
             break;
         case Y_PREF_IDENTIF_ARG:
-            LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, !already_read, &prefix));
+            LY_CHECK_RET(lysp_check_identifierchar((struct lys_parser_ctx *)ctx, c, already_read ? 0 : 1, &prefix));
             break;
         case Y_STR_ARG:
         case Y_MAYBE_STR_ARG:
@@ -378,9 +378,9 @@
  * @return Pointer to desired record on success, NULL if element is not in the array.
  */
 static struct yin_subelement *
-get_record(enum ly_stmt type, size_t array_size, struct yin_subelement *array)
+get_record(enum ly_stmt type, LY_ARRAY_COUNT_TYPE array_size, struct yin_subelement *array)
 {
-    for (unsigned int u = 0; u < array_size; ++u) {
+    for (LY_ARRAY_COUNT_TYPE u = 0; u < array_size; ++u) {
         if (array[u].type == type) {
             return &array[u];
         }
diff --git a/src/path.c b/src/path.c
index 5a65ada..88f24a9 100644
--- a/src/path.c
+++ b/src/path.c
@@ -697,7 +697,7 @@
     const struct lys_module *mod;
     const struct lysc_node *node2, *cur_node, *op;
     struct ly_path *p = NULL;
-    int getnext_opts;
+    uint32_t getnext_opts;
     const char *name;
     size_t name_len;
 
diff --git a/src/plugins_exts.c b/src/plugins_exts.c
index 94c97cd..9158e09 100644
--- a/src/plugins_exts.c
+++ b/src/plugins_exts.c
@@ -37,9 +37,7 @@
 struct lyext_plugin *
 lyext_get_plugin(struct lysc_ext *ext)
 {
-    unsigned int u;
-
-    for (u = 0; lyext_plugins_internal[u].module; ++u) {
+    for (uint8_t u = 0; lyext_plugins_internal[u].module; ++u) {
         if (!strcmp(ext->name, lyext_plugins_internal[u].name) &&
                 !strcmp(ext->module->name, lyext_plugins_internal[u].module) &&
                 (!lyext_plugins_internal[u].revision || !strcmp(ext->module->revision, lyext_plugins_internal[u].revision))) {
diff --git a/src/plugins_exts.h b/src/plugins_exts.h
index 8a4033b..40fd29e 100644
--- a/src/plugins_exts.h
+++ b/src/plugins_exts.h
@@ -41,7 +41,7 @@
  * @brief Macro to store version of extension plugins API in the plugins.
  * It is matched when the plugin is being loaded by libyang.
  */
-#define LYEXT_VERSION_CHECK int lyext_api_version = LYEXT_API_VERSION;
+#define LYEXT_VERSION_CHECK uint32_t lyext_api_version = LYEXT_API_VERSION;
 
 /**
  * @defgroup extensionscompile YANG Extensions - Compilation Helpers
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 9be990b..aec7306 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -174,7 +174,7 @@
  */
 static const char *
 ly_type_print_simple(const struct lyd_value *value, LY_PREFIX_FORMAT UNUSED(format),
-        void *UNUSED(prefix_data), int *dynamic)
+        void *UNUSED(prefix_data), uint8_t *dynamic)
 {
     *dynamic = 0;
     return (char *)value->canonical;
@@ -349,7 +349,7 @@
 
     if (len + trailing_zeros < value_len) {
         /* consume trailing whitespaces to check that there is nothing after it */
-        unsigned long int u;
+        uint64_t u;
         for (u = len + trailing_zeros; u < value_len && isspace(value[u]); ++u) {}
         if (u != value_len) {
             if (asprintf(&errmsg, "Invalid %lu. character of decimal64 value \"%.*s\".",
@@ -517,7 +517,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_int(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_int(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -573,7 +573,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_uint(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_uint(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -627,7 +627,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_decimal64(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_decimal64(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -656,7 +656,7 @@
              * for (num<0) - extra character for '-' sign */
             count = sprintf(buf, "%0*" PRId64 " ", (d > 0) ? (type_dec->fraction_digits + 1) : (type_dec->fraction_digits + 2), d);
         }
-        for (int i = type_dec->fraction_digits, j = 1; i > 0; i--) {
+        for (uint8_t i = type_dec->fraction_digits, j = 1; i > 0; i--) {
             if (j && i > 1 && buf[count - 2] == '0') {
                 /* we have trailing zero to skip */
                 buf[count - 1] = '\0';
@@ -693,14 +693,14 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_binary(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_binary(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
     size_t start = 0, stop = 0, count = 0, u, termination = 0;
     struct lysc_type_bin *type_bin = (struct lysc_type_bin *)type;
     char *errmsg;
-    int erc = 0;
+    int rc = 0;
 
     LY_CHECK_ARG_RET(ctx, value, LY_EINVAL);
 
@@ -744,7 +744,7 @@
                 }
                 if (!termination) {
                     /* error */
-                    erc = asprintf(&errmsg, "Invalid Base64 character (%c).", value[u]);
+                    rc = asprintf(&errmsg, "Invalid Base64 character (%c).", value[u]);
                     goto error;
                 }
             }
@@ -781,7 +781,7 @@
 
 error:
     if (!*err) {
-        if (erc == -1 || !errmsg) {
+        if (rc == -1 || !errmsg) {
             *err = ly_err_new(LY_LLERR, LY_EMEM, 0, "Memory allocation failed.", NULL, NULL);
         } else {
             *err = ly_err_new(LY_LLERR, LY_EVALID, LYVE_DATA, errmsg, NULL, NULL);
@@ -796,7 +796,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_string(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_string(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -836,7 +836,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_bits(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_bits(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -850,11 +850,11 @@
     LY_ARRAY_COUNT_TYPE u, v;
     char *errmsg = NULL;
     struct lysc_type_bits *type_bits = (struct lysc_type_bits *)type;
-    int iscanonical = 1;
+    uint8_t iscanonical = 1;
     size_t ws_count;
     size_t lws_count; /* leading whitespace count */
     const char *can = NULL;
-    int erc = 0;
+    int rc = 0;
 
     if (options & LY_TYPE_OPTS_SECOND_CALL) {
         return LY_SUCCESS;
@@ -886,7 +886,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]) == LY_ENOT) {
-                        erc = asprintf(&errmsg, "Bit \"%s\" is disabled by its %" LY_PRI_ARRAY_COUNT_TYPE ". if-feature condition.",
+                        rc = asprintf(&errmsg, "Bit \"%s\" is disabled by its %" LY_PRI_ARRAY_COUNT_TYPE ". if-feature condition.",
                                        type_bits->bits[u].name, v + 1);
                         goto error;
                     }
@@ -897,15 +897,15 @@
                 }
                 inserted = ly_set_add(items, &type_bits->bits[u], 0);
                 LY_CHECK_ERR_GOTO(inserted == -1, ret = LY_EMEM, error);
-                if ((unsigned int)inserted != items->count - 1) {
-                    erc = asprintf(&errmsg, "Bit \"%s\" used multiple times.", type_bits->bits[u].name);
+                if ((uint32_t)inserted != items->count - 1) {
+                    rc = asprintf(&errmsg, "Bit \"%s\" used multiple times.", type_bits->bits[u].name);
                     goto error;
                 }
                 goto next;
             }
         }
         /* item not found */
-        erc = asprintf(&errmsg, "Invalid bit value \"%.*s\".", (int)item_len, item);
+        rc = asprintf(&errmsg, "Invalid bit value \"%.*s\".", (int)item_len, item);
         goto error;
 next:
         /* remember for canonized form: item + space/termination-byte */
@@ -971,7 +971,7 @@
     return LY_SUCCESS;
 
 error:
-    if (erc == -1) {
+    if (rc == -1) {
         *err = ly_err_new(LY_LLERR, LY_EMEM, 0, "Memory allocation failed.", NULL, NULL);
         ret = LY_EMEM;
     } else if (errmsg) {
@@ -1025,14 +1025,14 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_enum(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_enum(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data), const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
     LY_ARRAY_COUNT_TYPE u, v;
     char *errmsg = NULL;
     struct lysc_type_enum *type_enum = (struct lysc_type_enum *)type;
-    int erc = 0;
+    int rc = 0;
 
     if (options & LY_TYPE_OPTS_SECOND_CALL) {
         return LY_SUCCESS;
@@ -1046,7 +1046,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]) == LY_ENOT) {
-                    erc = asprintf(&errmsg, "Enumeration \"%s\" is disabled by its %" LY_PRI_ARRAY_COUNT_TYPE ". if-feature condition.",
+                    rc = asprintf(&errmsg, "Enumeration \"%s\" is disabled by its %" LY_PRI_ARRAY_COUNT_TYPE ". if-feature condition.",
                                    type_enum->enums[u].name, v + 1);
                     goto error;
                 }
@@ -1055,7 +1055,7 @@
         }
     }
     /* enum not found */
-    erc = asprintf(&errmsg, "Invalid enumeration value \"%.*s\".", (int)value_len, value);
+    rc = asprintf(&errmsg, "Invalid enumeration value \"%.*s\".", (int)value_len, value);
     goto error;
 
 match:
@@ -1072,7 +1072,7 @@
     return LY_SUCCESS;
 
 error:
-    if (erc == -1) {
+    if (rc == -1) {
         *err = ly_err_new(LY_LLERR, LY_EMEM, 0, "Memory allocation failed.", NULL, NULL);
         return LY_EMEM;
     } else {
@@ -1088,7 +1088,7 @@
  */
 static LY_ERR
 ly_type_store_boolean(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len,
-        int options, LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data),
+        uint32_t options, LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data),
         const void *UNUSED(context_node), const struct lyd_node *UNUSED(tree),
         struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -1130,7 +1130,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_empty(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_empty(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT UNUSED(format), void *UNUSED(prefix_data),
         const void *UNUSED(context_node), const struct lyd_node *UNUSED(tree),
         struct lyd_value *storage, struct ly_err_item **err)
@@ -1186,7 +1186,7 @@
 }
 
 static const char *ly_type_print_identityref(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data,
-        int *dynamic);
+        uint8_t *dynamic);
 
 /**
  * @brief Validate, canonize and store value of the YANG built-in identiytref type.
@@ -1194,7 +1194,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_identityref(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_identityref(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT format, void *prefix_data, const void *UNUSED(context_node),
         const struct lyd_node *UNUSED(tree), struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -1205,7 +1205,8 @@
     const struct lys_module *mod;
     LY_ARRAY_COUNT_TYPE u;
     struct lysc_ident *ident = NULL, *identities;
-    int erc = 0, dyn;
+    int rc = 0;
+    uint8_t dyn;
 
     if (options & LY_TYPE_OPTS_SECOND_CALL) {
         return LY_SUCCESS;
@@ -1229,7 +1230,7 @@
 
     mod = ly_resolve_prefix(ctx, prefix, prefix_len, format, prefix_data);
     if (!mod) {
-        erc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - unable to map prefix to YANG schema.", (int)value_len, value);
+        rc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - unable to map prefix to YANG schema.", (int)value_len, value);
         goto error;
     }
     if (mod->compiled) {
@@ -1246,11 +1247,11 @@
     }
     if (u == LY_ARRAY_COUNT(identities)) {
         /* no match */
-        erc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity not found.", (int)value_len, value);
+        rc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity not found.", (int)value_len, value);
         goto error;
     } else if (!mod->compiled) {
         /* non-implemented module */
-        erc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity found in non-implemented module \"%s\".",
+        rc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity found in non-implemented module \"%s\".",
                         (int)value_len, value, mod->name);
         goto error;
     }
@@ -1264,7 +1265,7 @@
     }
     if (u == LY_ARRAY_COUNT(type_ident->bases)) {
         /* no match */
-        erc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity not accepted by the type specification.",
+        rc = asprintf(&errmsg, "Invalid identityref \"%.*s\" value - identity not accepted by the type specification.",
                         (int)value_len, value);
         goto error;
     }
@@ -1283,7 +1284,7 @@
     return LY_SUCCESS;
 
 error:
-    if (erc == -1 || !errmsg) {
+    if (rc == -1 || !errmsg) {
         *err = ly_err_new(LY_LLERR, LY_EMEM, 0, "Memory allocation failed.", NULL, NULL);
         return LY_EMEM;
     } else {
@@ -1312,7 +1313,7 @@
  * Implementation of the ly_type_print_clb.
  */
 static const char *
-ly_type_print_identityref(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, int *dynamic)
+ly_type_print_identityref(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, uint8_t *dynamic)
 {
     char *result = NULL;
 
@@ -1325,7 +1326,7 @@
 }
 
 static const char *ly_type_print_instanceid(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data,
-        int *dynamic);
+        uint8_t *dynamic);
 
 /**
  * @brief Validate and store value of the YANG built-in instance-identifier type.
@@ -1333,7 +1334,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_instanceid(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_instanceid(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT format, void *prefix_data, const void *context_node, const struct lyd_node *tree,
         struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -1344,7 +1345,9 @@
     struct ly_set predicates = {0};
     struct lyxp_expr *exp = NULL;
     const struct lysc_node *ctx_scnode;
-    int erc = 0, prefix_opt = 0, dyn;
+    int rc = 0;
+    uint32_t prefix_opt = 0;
+    uint8_t dyn;
 
     /* init */
     *err = NULL;
@@ -1373,9 +1376,9 @@
         if (ly_path_eval(storage->target, tree, NULL)) {
             /* in error message we print the JSON format of the instance-identifier - in case of XML, it is not possible
              * to get the exactly same string as original, JSON is less demanding and still well readable/understandable. */
-            int dynamic = 0;
+            uint8_t dynamic = 0;
             const char *id = storage->realtype->plugin->print(storage, LY_PREF_JSON, NULL, &dynamic);
-            erc = asprintf(&errmsg, "Invalid instance-identifier \"%s\" value - required instance not found.", id);
+            rc = asprintf(&errmsg, "Invalid instance-identifier \"%s\" value - required instance not found.", id);
             if (dynamic) {
                 free((char *)id);
             }
@@ -1391,7 +1394,7 @@
     ret = ly_path_parse(ctx, ctx_scnode, value, value_len, LY_PATH_BEGIN_ABSOLUTE, LY_PATH_LREF_FALSE,
                         prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
     if (ret) {
-        erc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - syntax error.", (int)value_len, value);
+        rc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - syntax error.", (int)value_len, value);
         goto error;
     }
 
@@ -1399,7 +1402,7 @@
     ret = ly_path_compile(ctx, ctx_scnode->module, NULL, exp, LY_PATH_LREF_FALSE, lysc_is_output(ctx_scnode) ?
                           LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_SINGLE, format, prefix_data, &path);
     if (ret) {
-        erc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - semantic error.", (int)value_len, value);
+        rc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - semantic error.", (int)value_len, value);
         goto error;
     }
 
@@ -1407,7 +1410,7 @@
     if (!(options & LY_TYPE_OPTS_INCOMPLETE_DATA) && !(options & LY_TYPE_OPTS_SCHEMA) && type_inst->require_instance) {
         ret = ly_path_eval(path, tree, NULL);
         if (ret) {
-            erc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - instance not found.", (int)value_len, value);
+            rc = asprintf(&errmsg, "Invalid instance-identifier \"%.*s\" value - instance not found.", (int)value_len, value);
             goto error;
         }
     }
@@ -1447,7 +1450,7 @@
     ly_path_free(ctx, path);
 
     if (!*err) {
-        if (erc == -1) {
+        if (rc == -1) {
             *err = ly_err_new(LY_LLERR, LY_EMEM, 0, "Memory allocation failed.", NULL, NULL);
             ret = LY_EMEM;
         } else {
@@ -1520,7 +1523,7 @@
  * Implementation of the ly_type_print_clb.
  */
 static const char *
-ly_type_print_instanceid(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, int *dynamic)
+ly_type_print_instanceid(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, uint8_t *dynamic)
 {
     LY_ARRAY_COUNT_TYPE u, v;
     char *result = NULL;
@@ -1547,7 +1550,7 @@
                 case LY_PATH_PREDTYPE_LIST:
                 {
                     /* key-predicate */
-                    int d = 0;
+                    uint8_t d = 0;
                     const char *value = pred->value.realtype->plugin->print(&pred->value, format, prefix_data, &d);
                     char quot = '\'';
                     if (strchr(value, quot)) {
@@ -1563,7 +1566,7 @@
                 case LY_PATH_PREDTYPE_LEAFLIST:
                 {
                     /* leaf-list-predicate */
-                    int d = 0;
+                    uint8_t d = 0;
                     const char *value = pred->value.realtype->plugin->print(&pred->value, format, prefix_data, &d);
                     char quot = '\'';
                     if (strchr(value, quot)) {
@@ -1600,7 +1603,7 @@
                 case LY_PATH_PREDTYPE_LIST:
                 {
                     /* key-predicate */
-                    int d = 0;
+                    uint8_t d = 0;
                     const char *value = pred->value.realtype->plugin->print(&pred->value, format, prefix_data, &d);
                     char quot = '\'';
                     if (strchr(value, quot)) {
@@ -1615,7 +1618,7 @@
                 case LY_PATH_PREDTYPE_LEAFLIST:
                 {
                     /* leaf-list-predicate */
-                    int d = 0;
+                    uint8_t d = 0;
                     const char *value = pred->value.realtype->plugin->print(&pred->value, format, prefix_data, &d);
                     char quot = '\'';
                     if (strchr(value, quot)) {
@@ -1673,7 +1676,7 @@
     LY_ERR ret;
     struct lyxp_set set = {0};
     const char *val_str;
-    int dynamic;
+    uint8_t dynamic;
     uint32_t i;
 
     /* find all target data instances */
@@ -1733,7 +1736,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_leafref(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_leafref(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT format, void *prefix_data, const void *context_node, const struct lyd_node *tree,
         struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -1810,7 +1813,7 @@
  * Implementation of the ly_type_print_clb.
  */
 static const char *
-ly_type_print_leafref(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, int *dynamic)
+ly_type_print_leafref(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, uint8_t *dynamic)
 {
     return value->realtype->plugin->print(value, format, prefix_data, dynamic);
 }
@@ -1843,7 +1846,7 @@
  * @brief Answer if the type is suitable for the parser's hit (if any) in the specified format
  */
 LY_ERR
-type_check_parser_hint(LY_PREFIX_FORMAT format, int hint, LY_DATA_TYPE type)
+type_check_parser_hint(LY_PREFIX_FORMAT format, uint32_t hint, LY_DATA_TYPE type)
 {
     if (format == LY_PREF_JSON && hint) {
         switch (type) {
@@ -1929,7 +1932,6 @@
 ly_type_union_store_prefix_data(const struct ly_ctx *ctx, const char *value, size_t value_len, LY_PREFIX_FORMAT format,
         void *prefix_data)
 {
-    unsigned int c;
     const char *start, *stop;
     const struct lys_module *mod;
     struct lyxml_ns *ns;
@@ -1955,6 +1957,8 @@
     /* add all used prefixes */
     for (stop = start = value; (size_t)(stop - value) < value_len; start = stop) {
         size_t bytes;
+        uint32_t c;
+
         ly_getutf8(&stop, &c, &bytes);
         if (is_xmlqnamestartchar(c)) {
             for (ly_getutf8(&stop, &c, &bytes);
@@ -2062,7 +2066,7 @@
  * Implementation of the ly_type_store_clb.
  */
 static LY_ERR
-ly_type_store_union(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, int options,
+ly_type_store_union(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len, uint32_t options,
         LY_PREFIX_FORMAT format, void *prefix_data, const void *context_node, const struct lyd_node *tree,
         struct lyd_value *storage, struct ly_err_item **err)
 {
@@ -2071,7 +2075,7 @@
     struct lysc_type_union *type_u = (struct lysc_type_union *)type;
     struct lyd_value_subvalue *subvalue;
     char *errmsg = NULL;
-    int prev_lo;
+    uint32_t prev_lo;
 
     if (options & LY_TYPE_OPTS_SECOND_CALL) {
         subvalue = storage->subvalue;
@@ -2187,7 +2191,7 @@
  * Implementation of the ly_type_print_clb.
  */
 static const char *
-ly_type_print_union(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, int *dynamic)
+ly_type_print_union(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data, uint8_t *dynamic)
 {
     return value->subvalue->value->realtype->plugin->print(value->subvalue->value, format, prefix_data, dynamic);
 }
diff --git a/src/plugins_types.h b/src/plugins_types.h
index 8efb320..885b6b0 100644
--- a/src/plugins_types.h
+++ b/src/plugins_types.h
@@ -201,7 +201,7 @@
  * @return LY_ERR value if an error occurred and the value could not be canonized following the type's rules.
  */
 typedef LY_ERR (*ly_type_store_clb)(const struct ly_ctx *ctx, struct lysc_type *type, const char *value, size_t value_len,
-        int options, LY_PREFIX_FORMAT format, void *prefix_data, const void *context_node,
+        uint32_t options, LY_PREFIX_FORMAT format, void *prefix_data, const void *context_node,
         const struct lyd_node *tree, struct lyd_value *storage, struct ly_err_item **err);
 
 /**
@@ -234,7 +234,7 @@
  * @return NULL in case of error.
  */
 typedef const char *(*ly_type_print_clb)(const struct lyd_value *value, LY_PREFIX_FORMAT format, void *prefix_data,
-        int *dynamic);
+        uint8_t *dynamic);
 
 /**
  * @brief Callback to duplicate data in data structure. Note that callback is even responsible for duplicating lyd_value::canonized.
diff --git a/src/printer.c b/src/printer.c
index 6272bb3..4b07b8b 100644
--- a/src/printer.c
+++ b/src/printer.c
@@ -71,7 +71,7 @@
     {"unique", "tag", 0},                       /**< LYEXT_SUBSTMT_UNIQUE */
 };
 
-int
+uint8_t
 ly_is_default(const struct lyd_node *node)
 {
     const struct lysc_node_leaf *leaf;
@@ -109,8 +109,8 @@
     return 1;
 }
 
-int
-ly_should_print(const struct lyd_node *node, int options)
+uint8_t
+ly_should_print(const struct lyd_node *node, uint32_t options)
 {
     const struct lyd_node *elem;
 
@@ -429,7 +429,7 @@
 }
 
 API void
-ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), int destroy)
+ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), uint8_t destroy)
 {
     if (!out) {
         return;
@@ -597,8 +597,8 @@
 LY_ERR
 ly_write_(struct ly_out *out, const char *buf, size_t len)
 {
-    LY_ERR ret;
-    int written = 0;
+    LY_ERR ret = LY_SUCCESS;
+    size_t written = 0;
 
     if (out->hole_count) {
         /* we are buffering data after a hole */
@@ -640,29 +640,46 @@
 
         written = len;
         break;
-    case LY_OUT_FD:
-        written = write(out->method.fd, buf, len);
+    case LY_OUT_FD: {
+        ssize_t r;
+        r = write(out->method.fd, buf, len);
+        if (r < 0) {
+            ret = LY_ESYS;
+        } else {
+            written = (size_t)r;
+        }
         break;
+    }
     case LY_OUT_FDSTREAM:
     case LY_OUT_FILEPATH:
     case LY_OUT_FILE:
         written = fwrite(buf, sizeof *buf, len, out->method.f);
+        if (written != len) {
+            ret = LY_ESYS;
+        }
         break;
-    case LY_OUT_CALLBACK:
-        written = out->method.clb.func(out->method.clb.arg, buf, len);
+    case LY_OUT_CALLBACK: {
+        ssize_t r;
+        r = out->method.clb.func(out->method.clb.arg, buf, len);
+        if (r < 0) {
+            ret = LY_ESYS;
+        } else {
+            written = (size_t)r;
+        }
         break;
+    }
     case LY_OUT_ERROR:
         LOGINT(NULL);
         return LY_EINT;
     }
 
-    if (written < 0) {
+    if (ret) {
         if (errno == EAGAIN || errno == EWOULDBLOCK) {
+            ret = LY_SUCCESS;
             goto repeat;
         }
         LOGERR(NULL, LY_ESYS, "%s: writing data failed (%s).", __func__, strerror(errno));
         written = 0;
-        ret = LY_ESYS;
     } else if ((size_t)written != len) {
         LOGERR(NULL, LY_ESYS, "%s: writing data failed (unable to write %u from %u data).", __func__,
                len - (size_t)written, len);
diff --git a/src/printer.h b/src/printer.h
index 5eb217d..3ffbef1 100644
--- a/src/printer.h
+++ b/src/printer.h
@@ -237,7 +237,7 @@
  * @param[in] destroy Flag to free allocated buffer (for LY_OUT_MEMORY) or to
  * close stream/file descriptor (for LY_OUT_FD, LY_OUT_FDSTREAM and LY_OUT_FILE)
  */
-void ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), int destroy);
+void ly_out_free(struct ly_out *out, void (*clb_arg_destructor)(void *arg), uint8_t destroy);
 
 #ifdef __cplusplus
 }
diff --git a/src/printer_data.c b/src/printer_data.c
index 50ac2e1..1cdc0c2 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -25,7 +25,7 @@
 #include "tree_schema.h"
 
 static LY_ERR
-lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret = LY_SUCCESS;
 
@@ -49,7 +49,7 @@
 }
 
 API LY_ERR
-lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
 
@@ -71,7 +71,7 @@
 }
 
 API LY_ERR
-lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_CHECK_ARG_RET(NULL, out, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
 
@@ -85,7 +85,7 @@
 }
 
 API LY_ERR
-lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret;
     struct ly_out *out;
@@ -102,7 +102,7 @@
 }
 
 API LY_ERR
-lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret;
     struct ly_out *out;
@@ -116,7 +116,7 @@
 }
 
 API LY_ERR
-lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret;
     struct ly_out *out;
@@ -130,7 +130,7 @@
 }
 
 API LY_ERR
-lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret;
     struct ly_out *out;
@@ -144,7 +144,7 @@
 }
 
 API LY_ERR
-lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, int options)
+lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, uint32_t options)
 {
     LY_ERR ret;
     struct ly_out *out;
diff --git a/src/printer_data.h b/src/printer_data.h
index 44e365f..6ff1e41 100644
--- a/src/printer_data.h
+++ b/src/printer_data.h
@@ -66,7 +66,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print the selected data subtree.
@@ -77,7 +77,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags) except ::LYD_PRINT_WITHSIBLINGS.
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print data tree in the specified format.
@@ -88,7 +88,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print data tree in the specified format.
@@ -99,7 +99,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print data tree in the specified format.
@@ -110,7 +110,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print data tree in the specified format.
@@ -121,7 +121,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 /**
  * @brief Print data tree in the specified format.
@@ -133,7 +133,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, int options);
+LY_ERR lyd_print_clb(ly_write_clb writeclb, void *user_data, const struct lyd_node *root, LYD_FORMAT format, uint32_t options);
 
 #ifdef __cplusplus
 }
diff --git a/src/printer_internal.h b/src/printer_internal.h
index 6740916..3703ad0 100644
--- a/src/printer_internal.h
+++ b/src/printer_internal.h
@@ -65,7 +65,7 @@
 struct ext_substmt_info_s {
     const char *name;      /**< name of the statement */
     const char *arg;       /**< name of YIN's attribute to present the statement */
-    int flags;             /**< various flags to clarify printing of the statement */
+    uint8_t flags;         /**< various flags to clarify printing of the statement */
 #define SUBST_FLAG_YIN 0x1 /**< has YIN element */
 #define SUBST_FLAG_ID 0x2  /**< the value is identifier -> no quotes */
 };
@@ -82,7 +82,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, int options);
+LY_ERR yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options);
 
 /**
  * @brief Helper macros for data printers
@@ -102,7 +102,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, int options);
+LY_ERR yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, uint32_t options);
 
 /**
  * @brief YANG printer of the compiled schemas.
@@ -116,7 +116,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yang_print_compiled(struct ly_out *out, const struct lys_module *module, int options);
+LY_ERR yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options);
 
 /**
  * @brief YANG printer of the compiled schema node
@@ -130,7 +130,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, int options);
+LY_ERR yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options);
 
 /**
  * @brief YIN printer of the parsed module. Full YIN printer.
@@ -141,7 +141,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, int options);
+LY_ERR yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options);
 
 /**
  * @brief YIN printer of the parsed submodule. Full YIN printer.
@@ -152,7 +152,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, int options);
+LY_ERR yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, uint32_t options);
 
 /**
  * @brief XML printer of YANG data.
@@ -162,7 +162,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR xml_print_data(struct ly_out *out, const struct lyd_node *root, int options);
+LY_ERR xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
 
 /**
  * @brief JSON printer of YANG data.
@@ -172,7 +172,7 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR json_print_data(struct ly_out *out, const struct lyd_node *root, int options);
+LY_ERR json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
 
 /**
  * @brief LYB printer of YANG data.
@@ -182,16 +182,16 @@
  * @param[in] options [Data printer flags](@ref dataprinterflags).
  * @return LY_ERR value, number of the printed bytes is updated in lyout::printed.
  */
-LY_ERR lyb_print_data(struct ly_out *out, const struct lyd_node *root, int options);
+LY_ERR lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options);
 
 /**
  * @brief Check whether a node value equals to its default one.
  *
  * @param[in] node Term node to test.
  * @return 0 if no,
- * @return non-zero if yes.
+ * @return 1 if yes.
  */
-int ly_is_default(const struct lyd_node *node);
+uint8_t ly_is_default(const struct lyd_node *node);
 
 /**
  * @brief Check whether the node should even be printed.
@@ -199,9 +199,9 @@
  * @param[in] node Node to check.
  * @param[in] options Printer options.
  * @return 0 if no.
- * @return non-zero if yes.
+ * @return 1 if yes.
  */
-int ly_should_print(const struct lyd_node *node, int options);
+uint8_t ly_should_print(const struct lyd_node *node, uint32_t options);
 
 /**
  * @brief Generic printer of the given format string into the specified output.
diff --git a/src/printer_json.c b/src/printer_json.c
index e411ab6..a0285b2 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -32,12 +32,12 @@
  * @brief JSON printer context.
  */
 struct jsonpr_ctx {
-    struct ly_out *out;  /**< output specification */
-    unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
-    int options;        /**< [Data printer flags](@ref dataprinterflags) */
-    const struct ly_ctx *ctx; /**< libyang context */
+    struct ly_out *out;         /**< output specification */
+    uint16_t level;             /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    uint32_t options;           /**< [Data printer flags](@ref dataprinterflags) */
+    const struct ly_ctx *ctx;   /**< libyang context */
 
-    unsigned int level_printed; /* level where some dara were already printed */
+    uint16_t level_printed;     /* level where some data were already printed */
     struct ly_set open; /* currently open array(s) */
     const struct lyd_node *print_sibling_metadata;
 };
@@ -218,7 +218,7 @@
 static LY_ERR
 json_print_string(struct ly_out *out, const char *text)
 {
-    unsigned int i, n;
+    uint64_t i, n;
 
     if (!text) {
         return LY_SUCCESS;
@@ -258,7 +258,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-json_print_member(struct jsonpr_ctx *ctx, const struct lyd_node *node, int is_attr)
+json_print_member(struct jsonpr_ctx *ctx, const struct lyd_node *node, uint8_t is_attr)
 {
     PRINT_COMMA;
     if (LEVEL == 1 || json_nscmp(node, (const struct lyd_node *)node->parent)) {
@@ -285,7 +285,8 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-json_print_member2(struct jsonpr_ctx *ctx, const struct lyd_node *parent, LYD_FORMAT format, const struct ly_prefix *prefix, const char *name, int is_attr)
+json_print_member2(struct jsonpr_ctx *ctx, const struct lyd_node *parent, LYD_FORMAT format,
+        const struct ly_prefix *prefix, const char *name, uint8_t is_attr)
 {
     const char *module_name = NULL;
 
@@ -332,7 +333,7 @@
 static LY_ERR
 json_print_value(struct jsonpr_ctx *ctx, const struct lyd_value *val)
 {
-    int dynamic = 0;
+    uint8_t dynamic = 0;
     const char *value = val->realtype->plugin->print(val, LY_PREF_JSON, NULL, &dynamic);
 
     /* leafref is not supported */
@@ -447,7 +448,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-json_print_attributes(struct jsonpr_ctx *ctx, const struct lyd_node *node, int inner)
+json_print_attributes(struct jsonpr_ctx *ctx, const struct lyd_node *node, uint8_t inner)
 {
     const struct lys_module *wdmod = NULL;
 
@@ -519,7 +520,7 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyd_node *iter;
-    int prev_opts, prev_lo;
+    uint32_t prev_opts, prev_lo;
 
     if (!any->value.tree) {
         /* no content */
@@ -527,7 +528,7 @@
     }
 
     if (any->value_type == LYD_ANYDATA_LYB) {
-        int parser_options = LYD_PARSE_ONLY | LYD_PARSE_OPAQ | LYD_PARSE_STRICT;
+        uint32_t parser_options = LYD_PARSE_ONLY | LYD_PARSE_OPAQ | LYD_PARSE_STRICT;
 
         /* turn logging off */
         prev_lo = ly_log_options(0);
@@ -588,7 +589,7 @@
 {
     struct lyd_node *child;
     struct lyd_node *children = lyd_node_children(node, 0);
-    int has_content = 0;
+    uint8_t has_content = 0;
 
     if (node->meta || children) {
         has_content = 1;
@@ -748,7 +749,7 @@
 static LY_ERR
 json_print_opaq(struct jsonpr_ctx *ctx, const struct lyd_node_opaq *node)
 {
-    int first = 1, last = 1;
+    uint8_t first = 1, last = 1;
 
     if (node->hint & LYD_NODE_OPAQ_ISLIST) {
         const struct lyd_node_opaq *prev = (const struct lyd_node_opaq *)node->prev;
@@ -851,7 +852,7 @@
 }
 
 LY_ERR
-json_print_data(struct ly_out *out, const struct lyd_node *root, int options)
+json_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options)
 {
     const struct lyd_node *node;
     struct jsonpr_ctx ctx = {0};
diff --git a/src/printer_lyb.c b/src/printer_lyb.c
index e5c1a3c..1e4b145 100644
--- a/src/printer_lyb.c
+++ b/src/printer_lyb.c
@@ -39,8 +39,8 @@
 /**
  * @brief Hash table equal callback for checking hash equality only.
  */
-static int
-lyb_hash_equal_cb(void *UNUSED(val1_p), void *UNUSED(val2_p), int UNUSED(mod), void *UNUSED(cb_data))
+static uint8_t
+lyb_hash_equal_cb(void *UNUSED(val1_p), void *UNUSED(val2_p), uint8_t UNUSED(mod), void *UNUSED(cb_data))
 {
     /* for this purpose, if hash matches, the value does also, we do not want 2 values to have the same hash */
     return 1;
@@ -49,8 +49,8 @@
 /**
  * @brief Hash table equal callback for checking value pointer equality only.
  */
-static int
-lyb_ptr_equal_cb(void *val1_p, void *val2_p, int UNUSED(mod), void *UNUSED(cb_data))
+static uint8_t
+lyb_ptr_equal_cb(void *val1_p, void *val2_p, uint8_t UNUSED(mod), void *UNUSED(cb_data))
 {
     struct lysc_node *val1 = *(struct lysc_node **)val1_p;
     struct lysc_node *val2 = *(struct lysc_node **)val2_p;
@@ -72,9 +72,8 @@
  * @return LY_EEXIST when the whole hash sequence sollides.
  */
 static LY_ERR
-lyb_hash_sequence_check(struct hash_table *ht, struct lysc_node *sibling, int ht_col_id, int compare_col_id)
+lyb_hash_sequence_check(struct hash_table *ht, struct lysc_node *sibling, LYB_HASH ht_col_id, LYB_HASH compare_col_id)
 {
-    int j;
     struct lysc_node **col_node;
 
     /* get the first node inserted with last hash col ID ht_col_id */
@@ -85,7 +84,8 @@
 
     lyht_set_cb(ht, lyb_ptr_equal_cb);
     do {
-        for (j = compare_col_id; j > -1; --j) {
+        int64_t j;
+        for (j = (int64_t)compare_col_id; j > -1; --j) {
             if (lyb_hash(sibling, j) != lyb_hash(*col_node, j)) {
                 /* one non-colliding hash */
                 break;
@@ -117,7 +117,7 @@
     struct hash_table *ht;
     const struct lysc_node *parent;
     const struct lys_module *mod;
-    int i, j;
+    LYB_HASH i;
 
     ht = lyht_new(1, sizeof(struct lysc_node *), lyb_hash_equal_cb, NULL, 1);
     LY_CHECK_ERR_RET(!ht, LOGMEM(sibling->module->ctx), LY_EMEM);
@@ -131,8 +131,9 @@
         /* find the first non-colliding hash (or specifically non-colliding hash sequence) */
         for (i = 0; i < LYB_HASH_BITS; ++i) {
             /* check that we are not colliding with nodes inserted with a lower collision ID than ours */
-            for (j = i - 1; j > -1; --j) {
-                if (lyb_hash_sequence_check(ht, sibling, j, i)) {
+            int64_t j;
+            for (j = (int64_t)i - 1; j > -1; --j) {
+                if (lyb_hash_sequence_check(ht, sibling, (LYB_HASH)j, i)) {
                     break;
                 }
             }
@@ -378,7 +379,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyb_write_string(const char *str, size_t str_len, int with_length, struct ly_out *out, struct lylyb_ctx *lybctx)
+lyb_write_string(const char *str, size_t str_len, uint8_t with_length, struct ly_out *out, struct lylyb_ctx *lybctx)
 {
     if (!str) {
         str = "";
@@ -413,7 +414,6 @@
 static LY_ERR
 lyb_print_model(struct ly_out *out, const struct lys_module *mod, struct lylyb_ctx *lybctx)
 {
-    int r;
     uint16_t revision;
 
     /* model name length and model name */
@@ -427,7 +427,7 @@
      *                   YYYY YYYM MMMD DDDD */
     revision = 0;
     if (mod && mod->revision) {
-        r = atoi(mod->revision);
+        int r = atoi(mod->revision);
         r -= 2000;
         r <<= 9;
 
@@ -934,7 +934,7 @@
 }
 
 LY_ERR
-lyb_print_data(struct ly_out *out, const struct lyd_node *root, int options)
+lyb_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options)
 {
     LY_ERR ret = LY_SUCCESS;
     uint8_t zero = 0;
diff --git a/src/printer_schema.c b/src/printer_schema.c
index f59676a..99a947a 100644
--- a/src/printer_schema.c
+++ b/src/printer_schema.c
@@ -25,8 +25,8 @@
 #include "tree_schema.h"
 
 API LY_ERR
-lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int UNUSED(line_length),
-        int options)
+lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, size_t UNUSED(line_length),
+        uint32_t options)
 {
     LY_ERR ret;
 
@@ -82,7 +82,7 @@
 
 API LY_ERR
 lys_print_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodule,
-        LYS_OUTFORMAT format, int UNUSED(line_length), int options)
+        LYS_OUTFORMAT format, size_t UNUSED(line_length), uint32_t options)
 {
     LY_ERR ret;
 
@@ -116,7 +116,7 @@
 }
 
 static LY_ERR
-lys_print_(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     LY_ERR ret;
 
@@ -129,7 +129,7 @@
 }
 
 API LY_ERR
-lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     struct ly_out *out;
 
@@ -143,7 +143,7 @@
 }
 
 API LY_ERR
-lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     struct ly_out *out;
 
@@ -154,7 +154,7 @@
 }
 
 API LY_ERR
-lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     struct ly_out *out;
 
@@ -165,7 +165,7 @@
 }
 
 API LY_ERR
-lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     struct ly_out *out;
 
@@ -176,7 +176,7 @@
 }
 
 API LY_ERR
-lys_print_clb(ly_write_clb writeclb, void *user_data, const struct lys_module *module, LYS_OUTFORMAT format, int options)
+lys_print_clb(ly_write_clb writeclb, void *user_data, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options)
 {
     struct ly_out *out;
 
@@ -187,7 +187,7 @@
 }
 
 API LY_ERR
-lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, int UNUSED(line_length), int options)
+lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, size_t UNUSED(line_length), uint32_t options)
 {
     LY_ERR ret;
 
diff --git a/src/printer_schema.h b/src/printer_schema.h
index 1a7dfc3..c58c37c 100644
--- a/src/printer_schema.h
+++ b/src/printer_schema.h
@@ -71,7 +71,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
+LY_ERR lys_print_module(struct ly_out *out, const struct lys_module *module, LYS_OUTFORMAT format, size_t line_length, uint32_t options);
 
 /**
  * @brief Schema submodule printer.
@@ -85,7 +85,7 @@
  * @return LY_ERR value.
  */
 LY_ERR lys_print_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodule,
-        LYS_OUTFORMAT format, int line_length, int options);
+        LYS_OUTFORMAT format, size_t line_length, uint32_t options);
 
 /**
  * @brief Print schema tree in the specified format into a memory block.
@@ -100,7 +100,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int options);
+LY_ERR lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options);
 
 /**
  * @brief Print schema tree in the specified format into a file descriptor.
@@ -114,7 +114,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int options);
+LY_ERR lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options);
 
 /**
  * @brief Print schema tree in the specified format into a file stream.
@@ -128,7 +128,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int options);
+LY_ERR lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options);
 
 /**
  * @brief Print schema tree in the specified format into a file.
@@ -142,7 +142,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int options);
+LY_ERR lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options);
 
 /**
  * @brief Print schema tree in the specified format using a provided callback.
@@ -158,7 +158,7 @@
  * @return LY_ERR value.
  */
 LY_ERR lys_print_clb(ly_write_clb writeclb, void *user_data,
-        const struct lys_module *module, LYS_OUTFORMAT format, int options);
+        const struct lys_module *module, LYS_OUTFORMAT format, uint32_t options);
 
 /**
  * @brief Schema node printer.
@@ -170,7 +170,7 @@
  * @param[in] options Schema output options (see @ref schemaprinterflags).
  * @return LY_ERR value.
  */
-LY_ERR lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, int line_length, int options);
+LY_ERR lys_print_node(struct ly_out *out, const struct lysc_node *node, LYS_OUTFORMAT format, size_t line_length, uint32_t options);
 
 /** @} schematree */
 
diff --git a/src/printer_xml.c b/src/printer_xml.c
index ad878e7..7ac4a1f 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -36,12 +36,12 @@
  * @brief XML printer context.
  */
 struct xmlpr_ctx {
-    struct ly_out *out;  /**< output specification */
-    unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
-    int options;        /**< [Data printer flags](@ref dataprinterflags) */
+    struct ly_out *out;       /**< output specification */
+    uint16_t level;           /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    uint32_t options;         /**< [Data printer flags](@ref dataprinterflags) */
     const struct ly_ctx *ctx; /**< libyang context */
-    struct ly_set prefix;   /**< printed namespace prefixes */
-    struct ly_set ns;   /**< printed namespaces */
+    struct ly_set prefix;     /**< printed namespace prefixes */
+    struct ly_set ns;         /**< printed namespaces */
 };
 
 #define LYXML_PREFIX_REQUIRED 0x01  /**< The prefix is not just a suggestion but a requirement. */
@@ -57,11 +57,11 @@
  * @return Printed prefix of the namespace to use.
  */
 static const char *
-xml_print_ns(struct xmlpr_ctx *ctx, const char *ns, const char *new_prefix, int prefix_opts)
+xml_print_ns(struct xmlpr_ctx *ctx, const char *ns, const char *new_prefix, uint32_t prefix_opts)
 {
-    int i;
+    int64_t i;
 
-    for (i = ctx->ns.count - 1; i > -1; --i) {
+    for (i = (int64_t)ctx->ns.count - 1; i > -1; --i) {
         if (!new_prefix) {
             /* find default namespace */
             if (!ctx->prefix.objs[i]) {
@@ -104,7 +104,7 @@
 }
 
 static const char *
-xml_print_ns_opaq(struct xmlpr_ctx *ctx, LYD_FORMAT format, const struct ly_prefix *prefix, int prefix_opts)
+xml_print_ns_opaq(struct xmlpr_ctx *ctx, LYD_FORMAT format, const struct ly_prefix *prefix, uint32_t prefix_opts)
 {
 
     switch (format) {
@@ -141,12 +141,11 @@
     const char **prefs, **nss;
     const char *xml_expr = NULL, *mod_name;
     uint32_t ns_count, i;
-    int rpc_filter = 0;
+    uint8_t rpc_filter = 0;
     char *p;
     size_t len;
 #endif
-    int dynamic;
-    unsigned int u;
+    uint8_t dynamic;
 
     /* with-defaults */
     if (node->schema->nodetype & LYD_NODE_TERM) {
@@ -170,7 +169,7 @@
         const char *value = meta->value.realtype->plugin->print(&meta->value, LY_PREF_XML, &ns_list, &dynamic);
 
         /* print namespaces connected with the value's prefixes */
-        for (u = 0; u < ns_list.count; ++u) {
+        for (uint32_t u = 0; u < ns_list.count; ++u) {
             mod = (const struct lys_module *)ns_list.objs[u];
             xml_print_ns(ctx, mod->ns, mod->prefix, 1);
         }
@@ -290,15 +289,14 @@
 xml_print_term(struct xmlpr_ctx *ctx, const struct lyd_node_term *node)
 {
     struct ly_set ns_list = {0};
-    unsigned int u;
-    int dynamic;
+    uint8_t dynamic;
     const char *value;
 
     xml_print_node_open(ctx, (struct lyd_node *)node);
     value = ((struct lysc_node_leaf *)node->schema)->type->plugin->print(&node->value, LY_PREF_XML, &ns_list, &dynamic);
 
     /* print namespaces connected with the values's prefixes */
-    for (u = 0; u < ns_list.count; ++u) {
+    for (uint32_t u = 0; u < ns_list.count; ++u) {
         const struct lys_module *mod = (const struct lys_module *)ns_list.objs[u];
         ly_print_(ctx->out, " xmlns:%s=\"%s\"", mod->prefix, mod->ns);
     }
@@ -356,7 +354,7 @@
 {
     struct lyd_node_any *any = (struct lyd_node_any *)node;
     struct lyd_node *iter;
-    int prev_opts, prev_lo;
+    uint32_t prev_opts, prev_lo;
     LY_ERR ret;
 
     xml_print_node_open(ctx, (struct lyd_node *)node);
@@ -535,7 +533,7 @@
 }
 
 LY_ERR
-xml_print_data(struct ly_out *out, const struct lyd_node *root, int options)
+xml_print_data(struct ly_out *out, const struct lyd_node *root, uint32_t options)
 {
     const struct lyd_node *node;
     struct xmlpr_ctx ctx = {0};
diff --git a/src/printer_yang.c b/src/printer_yang.c
index 77deb2b..a13b3d8 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -45,11 +45,11 @@
  * @brief YANG printer context.
  */
 struct ypr_ctx {
-    struct ly_out *out;               /**< output specification */
-    unsigned int level;              /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    struct ly_out *out;              /**< output specification */
+    uint16_t level;                  /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    uint32_t options;                /**< Schema output options (see @ref schemaprinterflags). */
     const struct lys_module *module; /**< schema to print */
     enum schema_type schema;         /**< type of the schema to print */
-    int options;                     /**< Schema output options (see @ref schemaprinterflags). */
 };
 
 /**
@@ -65,9 +65,9 @@
  * the @p text is printed completely as a NULL-terminated string.
  */
 static void
-ypr_encode(struct ly_out *out, const char *text, int len)
+ypr_encode(struct ly_out *out, const char *text, ssize_t len)
 {
-    int i, start_len;
+    size_t i, start_len;
     const char *start;
     char special = 0;
 
@@ -81,7 +81,7 @@
 
     start = text;
     start_len = 0;
-    for (i = 0; i < len; ++i) {
+    for (i = 0; i < (size_t)len; ++i) {
         switch (text[i]) {
         case '\n':
         case '\t':
@@ -122,7 +122,7 @@
 }
 
 static void
-ypr_open(struct ly_out *out, int *flag)
+ypr_open(struct ly_out *out, uint8_t *flag)
 {
     if (flag && !*flag) {
         *flag = 1;
@@ -131,7 +131,7 @@
 }
 
 static void
-ypr_close(struct ypr_ctx *ctx, int flag)
+ypr_close(struct ypr_ctx *ctx, uint8_t flag)
 {
     if (flag) {
         ly_print_(ctx->out, "%*s}\n", INDENT);
@@ -141,7 +141,7 @@
 }
 
 static void
-ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
+ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, uint8_t singleline, uint8_t closed)
 {
     const char *s, *t;
 
@@ -219,11 +219,11 @@
  */
 static void
 yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-        struct lysp_ext_instance *ext, int *flag, LY_ARRAY_COUNT_TYPE count)
+        struct lysp_ext_instance *ext, uint8_t *flag, LY_ARRAY_COUNT_TYPE count)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysp_stmt *stmt;
-    int child_presence;
+    uint8_t child_presence;
     const char *argument;
 
     if (!count && ext) {
@@ -285,7 +285,7 @@
  */
 static void
 yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-        struct lysc_ext_instance *ext, int *flag, LY_ARRAY_COUNT_TYPE count)
+        struct lysc_ext_instance *ext, uint8_t *flag, LY_ARRAY_COUNT_TYPE count)
 {
     LY_ARRAY_COUNT_TYPE u;
 
@@ -310,7 +310,7 @@
 ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int extflag = 0;
+    uint8_t extflag = 0;
 
     if (!text) {
         /* nothing to print */
@@ -340,11 +340,11 @@
 }
 
 static void
-ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value, int *flag)
+ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value, uint8_t *flag)
 {
     char *str;
 
-    if (asprintf(&str, "%u", attr_value) == -1) {
+    if (asprintf(&str, "%lu", attr_value) == -1) {
         LOGMEM(ctx->module->ctx);
         return;
     }
@@ -354,11 +354,11 @@
 }
 
 static void
-ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value, int *flag)
+ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed long int attr_value, uint8_t *flag)
 {
     char *str;
 
-    if (asprintf(&str, "%d", attr_value) == -1) {
+    if (asprintf(&str, "%ld", attr_value) == -1) {
         LOGMEM(ctx->module->ctx);
         return;
     }
@@ -384,7 +384,7 @@
 }
 
 static void
-ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, uint8_t *flag)
 {
     if (flags & LYS_MAND_MASK) {
         ypr_open(ctx->out, flag);
@@ -393,7 +393,7 @@
 }
 
 static void
-ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, uint8_t *flag)
 {
     if (flags & LYS_CONFIG_MASK) {
         ypr_open(ctx->out, flag);
@@ -402,7 +402,7 @@
 }
 
 static void
-ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, uint8_t *flag)
 {
     const char *status = NULL;
 
@@ -421,7 +421,7 @@
 }
 
 static void
-ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
+ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, uint8_t *flag)
 {
     if (dsc) {
         ypr_open(ctx->out, flag);
@@ -430,7 +430,7 @@
 }
 
 static void
-ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
+ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, uint8_t *flag)
 {
     if (ref) {
         ypr_open(ctx->out, flag);
@@ -439,10 +439,10 @@
 }
 
 static void
-yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
+yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int extflag;
+    uint8_t extflag;
 
     LY_ARRAY_FOR(iff, u) {
         ypr_open(ctx->out, flag);
@@ -464,9 +464,9 @@
 }
 
 static void
-yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
+yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, size_t *index_e, size_t *index_f)
 {
-    int brackets_flag = *index_e;
+    uint8_t brackets_flag = *index_e ? 1 : 0;
     uint8_t op;
 
     op = lysc_iff_getop(feat->expr, *index_e);
@@ -507,13 +507,13 @@
 }
 
 static void
-yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
+yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u, v;
-    int extflag;
+    uint8_t extflag;
 
     LY_ARRAY_FOR(iff, u) {
-        int index_e = 0, index_f = 0;
+        size_t index_e = 0, index_f = 0;
 
         ypr_open(ctx->out, flag);
         extflag = 0;
@@ -538,7 +538,7 @@
 static void
 yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
 {
-    int flag = 0, flag2 = 0;
+    uint8_t flag = 0, flag2 = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     ly_print_(ctx->out, "%*sextension %s", INDENT, ext->name);
@@ -578,7 +578,7 @@
 static void
 yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
 {
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
     LEVEL++;
@@ -594,7 +594,7 @@
 static void
 yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
 {
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
     LEVEL++;
@@ -610,7 +610,7 @@
 static void
 yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
@@ -635,7 +635,7 @@
 static void
 yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
@@ -662,9 +662,9 @@
 }
 
 static void
-yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
+yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
 
     if (!restr) {
         return;
@@ -698,9 +698,9 @@
 }
 
 static void
-yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
+yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
 
     ypr_open(ctx->out, flag);
     ly_print_(ctx->out, "%*smust \"", INDENT);
@@ -725,9 +725,9 @@
 }
 
 static void
-yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
+yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     if (!range) {
@@ -774,9 +774,9 @@
 }
 
 static void
-yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
+yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
 
     ypr_open(ctx->out, flag);
     ly_print_(ctx->out, "%*spattern \"", INDENT);
@@ -806,9 +806,9 @@
 }
 
 static void
-yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
+yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
 
     if (!when) {
         return;
@@ -828,9 +828,9 @@
 }
 
 static void
-yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
+yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, uint8_t *flag)
 {
-    int inner_flag = 0;
+    uint8_t inner_flag = 0;
 
     if (!when) {
         return;
@@ -850,10 +850,10 @@
 }
 
 static void
-yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
+yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int inner_flag;
+    uint8_t inner_flag;
 
     LY_ARRAY_FOR(items, u) {
         ypr_open(ctx->out, flag);
@@ -887,7 +887,7 @@
 yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "%*stype %s", INDENT, type->name);
     LEVEL++;
@@ -929,7 +929,7 @@
 static void
 yprc_dflt_value(struct ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
 {
-    int dynamic;
+    uint8_t dynamic;
     const char *str;
 
     str = value->realtype->plugin->print(value, LY_PREF_JSON, NULL, &dynamic);
@@ -943,7 +943,7 @@
 yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
     LEVEL++;
@@ -982,7 +982,7 @@
         struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
         LY_ARRAY_FOR(bits->bits, u) {
             struct lysc_type_bitenum_item *item = &bits->bits[u];
-            int inner_flag = 0;
+            uint8_t inner_flag = 0;
 
             ypr_open(ctx->out, &flag);
             ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
@@ -1086,7 +1086,7 @@
 yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *data;
 
     ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
@@ -1121,7 +1121,7 @@
 }
 
 static void
-yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
+yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysp_node *data;
@@ -1155,7 +1155,7 @@
 }
 
 static void
-yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
+yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysc_node *data;
@@ -1188,7 +1188,7 @@
 yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *data;
 
     ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
@@ -1227,7 +1227,7 @@
 yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node *data;
 
     ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
@@ -1258,7 +1258,7 @@
 yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
 
@@ -1289,7 +1289,7 @@
 static void
 yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
 {
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
 
@@ -1308,7 +1308,7 @@
 }
 
 static void
-yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
+yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, uint8_t *flag)
 {
     ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
     LEVEL++;
@@ -1319,7 +1319,7 @@
 }
 
 static void
-yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
+yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, uint8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
 
@@ -1344,13 +1344,13 @@
     ypr_reference(ctx, node->ref, node->exts, flag)
 
 static void
-yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
+yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, uint8_t *flag)
 {
     YPR_NODE_COMMON2;
 }
 
 static void
-yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
+yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, uint8_t *flag)
 {
     YPR_NODE_COMMON2;
 }
@@ -1361,7 +1361,7 @@
 yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_container *cont = (struct lysp_node_container *)node;
 
@@ -1410,7 +1410,7 @@
 yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node *child;
     struct lysc_node_container *cont = (struct lysc_node_container *)node;
 
@@ -1450,7 +1450,7 @@
 static void
 yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_case *cas = (struct lysp_node_case *)node;
 
@@ -1469,7 +1469,7 @@
 static void
 yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node *child;
 
     yprc_node_common1(ctx, (struct lysc_node *)cs, &flag);
@@ -1489,7 +1489,7 @@
 static void
 yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
 
@@ -1514,7 +1514,7 @@
 static void
 yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node_case *cs;
     struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
 
@@ -1663,7 +1663,7 @@
 yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_list *list = (struct lysp_node_list *)node;
 
@@ -1735,7 +1735,7 @@
 yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
     LY_ARRAY_COUNT_TYPE u, v;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node *child;
     struct lysc_node_list *list = (struct lysc_node_list *)node;
 
@@ -1801,7 +1801,7 @@
 yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
 
     ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
     LEVEL++;
@@ -1883,7 +1883,7 @@
 yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
 
     yprp_node_common1(ctx, node, &flag);
@@ -1907,7 +1907,7 @@
 yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
 
     yprp_node_common1(ctx, node, &flag);
@@ -1927,7 +1927,7 @@
 yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    uint8_t flag = 0;
     struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
 
     yprc_node_common1(ctx, node, &flag);
@@ -2199,7 +2199,7 @@
 }
 
 LY_ERR
-yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, int options)
+yang_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED, .options = options | LYD_PRINT_FORMAT}, *ctx = &ctx_;
@@ -2256,7 +2256,7 @@
 }
 
 LY_ERR
-yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, int options)
+yang_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, uint32_t options)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED, .options = options | LYD_PRINT_FORMAT}, *ctx = &ctx_;
@@ -2301,7 +2301,7 @@
 }
 
 LY_ERR
-yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, int options)
+yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
 {
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options | LYD_PRINT_FORMAT}, *ctx = &ctx_;
 
@@ -2312,7 +2312,7 @@
 }
 
 LY_ERR
-yang_print_compiled(struct ly_out *out, const struct lys_module *module, int options)
+yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysc_node *data;
diff --git a/src/printer_yin.c b/src/printer_yin.c
index bef314a..7a42cb0 100644
--- a/src/printer_yin.c
+++ b/src/printer_yin.c
@@ -33,17 +33,17 @@
  * @brief YIN printer context.
  */
 struct ypr_ctx {
-    struct ly_out *out;               /**< output specification */
-    unsigned int level;              /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    struct ly_out *out;              /**< output specification */
+    uint16_t level;                  /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
+    uint32_t options;                /**< Schema output options (see @ref schemaprinterflags). */
     const struct lys_module *module; /**< schema to print */
-    int options;                     /**< Schema output options (see @ref schemaprinterflags). */
 };
 
 static void yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-        struct lysp_ext_instance *ext, int *flag, LY_ARRAY_COUNT_TYPE count);
+        struct lysp_ext_instance *ext, int8_t *flag, LY_ARRAY_COUNT_TYPE count);
 
 static void
-ypr_open(struct ypr_ctx *ctx, const char *elem_name, const char *attr_name, const char *attr_value, int flag)
+ypr_open(struct ypr_ctx *ctx, const char *elem_name, const char *attr_name, const char *attr_value, int8_t flag)
 {
     ly_print_(ctx->out, "%*s<%s", INDENT, elem_name);
 
@@ -57,7 +57,7 @@
 }
 
 static void
-ypr_close(struct ypr_ctx *ctx, const char *elem_name, int flag)
+ypr_close(struct ypr_ctx *ctx, const char *elem_name, int8_t flag)
 {
     if (flag) {
         ly_print_(ctx->out, "%*s</%s>\n", INDENT, elem_name);
@@ -72,7 +72,7 @@
  * 1 or NULL - parent already closed, do nothing
  */
 static void
-ypr_close_parent(struct ypr_ctx *ctx, int *par_close_flag)
+ypr_close_parent(struct ypr_ctx *ctx, int8_t *par_close_flag)
 {
     if (par_close_flag && !(*par_close_flag)) {
         (*par_close_flag) = 1;
@@ -92,7 +92,7 @@
 ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int extflag = 0;
+    int8_t extflag = 0;
 
     if (!text) {
         /* nothing to print */
@@ -124,10 +124,10 @@
 }
 
 static void
-ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value)
+ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value)
 {
     char *str;
-    if (asprintf(&str, "%u", attr_value) == -1) {
+    if (asprintf(&str, "%lu", attr_value) == -1) {
         LOGMEM(ctx->module->ctx);
         return;
     }
@@ -136,11 +136,11 @@
 }
 
 static void
-ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value)
+ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed long int attr_value)
 {
     char *str;
 
-    if (asprintf(&str, "%d", attr_value) == -1) {
+    if (asprintf(&str, "%ld", attr_value) == -1) {
         LOGMEM(ctx->module->ctx);
         return;
     }
@@ -165,7 +165,7 @@
 }
 
 static void
-ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int8_t *flag)
 {
     if (flags & LYS_MAND_MASK) {
         ypr_close_parent(ctx, flag);
@@ -174,7 +174,7 @@
 }
 
 static void
-ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int8_t *flag)
 {
     if (flags & LYS_CONFIG_MASK) {
         ypr_close_parent(ctx, flag);
@@ -183,7 +183,7 @@
 }
 
 static void
-ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
+ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int8_t *flag)
 {
     const char *status = NULL;
 
@@ -202,7 +202,7 @@
 }
 
 static void
-ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
+ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int8_t *flag)
 {
     if (dsc) {
         ypr_close_parent(ctx, flag);
@@ -211,7 +211,7 @@
 }
 
 static void
-ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
+ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int8_t *flag)
 {
     if (ref) {
         ypr_close_parent(ctx, flag);
@@ -220,10 +220,10 @@
 }
 
 static void
-yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
+yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int extflag;
+    int8_t extflag;
 
     LY_ARRAY_FOR(iff, u) {
         ypr_close_parent(ctx, flag);
@@ -247,7 +247,7 @@
 static void
 yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
 {
-    int flag = 0, flag2 = 0;
+    int8_t flag = 0, flag2 = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     ypr_open(ctx, "extension", "name", ext->name, flag);
@@ -290,7 +290,7 @@
 static void
 yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
 {
-    int flag = 0;
+    int8_t flag = 0;
 
     ypr_open(ctx, "feature", "name", feat->name, flag);
     LEVEL++;
@@ -306,7 +306,7 @@
 static void
 yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
 {
-    int flag = 0;
+    int8_t flag = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     ypr_open(ctx, "identity", "name", ident->name, flag);
@@ -329,10 +329,10 @@
 }
 
 static void
-yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, const char *attr, int *flag)
+yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, const char *attr, int8_t *flag)
 {
     (void)flag;
-    int inner_flag = 0;
+    int8_t inner_flag = 0;
 
     if (!restr) {
         return;
@@ -365,9 +365,9 @@
 }
 
 static void
-yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
+yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int8_t *flag)
 {
-    int inner_flag = 0;
+    int8_t inner_flag = 0;
     (void)flag;
 
     if (!when) {
@@ -387,10 +387,10 @@
 }
 
 static void
-yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
+yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int inner_flag;
+    int8_t inner_flag;
     (void)flag;
 
     LY_ARRAY_FOR(items, u) {
@@ -428,7 +428,7 @@
 yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
 
     if (!ctx || !type) {
         return;
@@ -507,7 +507,7 @@
 yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *data;
 
     ypr_open(ctx, "grouping", "name", grp->name, flag);
@@ -543,7 +543,7 @@
 }
 
 static void
-yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
+yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int8_t *flag)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysp_node *data;
@@ -580,7 +580,7 @@
 yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *data;
 
     ypr_open(ctx, "notification", "name", notif->name, flag);
@@ -620,7 +620,7 @@
 yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
 
     ypr_open(ctx, action->parent ? "action" : "rpc", "name", action->name, flag);
 
@@ -649,7 +649,7 @@
 }
 
 static void
-yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
+yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int8_t *flag)
 {
     ypr_open(ctx, lys_nodetype2str(node->nodetype), "name", node->name, *flag);
     LEVEL++;
@@ -660,7 +660,7 @@
 }
 
 static void
-yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
+yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int8_t *flag)
 {
     ypr_config(ctx, node->flags, node->exts, flag);
     if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) {
@@ -675,7 +675,7 @@
 yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_container *cont = (struct lysp_node_container *)node;
 
@@ -724,7 +724,7 @@
 static void
 yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_case *cas = (struct lysp_node_case *)node;
 
@@ -743,7 +743,7 @@
 static void
 yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
 
@@ -771,7 +771,7 @@
     LY_ARRAY_COUNT_TYPE u;
     struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
 
-    int flag = 1;
+    int8_t flag = 1;
     yprp_node_common1(ctx, node, &flag);
 
     yprp_type(ctx, &leaf->type);
@@ -792,7 +792,7 @@
 {
     LY_ARRAY_COUNT_TYPE u;
     struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
-    int flag = 1;
+    int8_t flag = 1;
 
     yprp_node_common1(ctx, node, &flag);
 
@@ -834,7 +834,7 @@
 yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node *child;
     struct lysp_node_list *list = (struct lysp_node_list *)node;
 
@@ -908,7 +908,7 @@
 yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
 
     ypr_open(ctx, "refine", "target-node", refine->nodeid, flag);
     LEVEL++;
@@ -990,7 +990,7 @@
 yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
 
     yprp_node_common1(ctx, node, &flag);
@@ -1014,7 +1014,7 @@
 yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
 {
     LY_ARRAY_COUNT_TYPE u;
-    int flag = 0;
+    int8_t flag = 0;
     struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
 
     yprp_node_common1(ctx, node, &flag);
@@ -1170,14 +1170,14 @@
 }
 
 static void
-ypr_xmlns(struct ypr_ctx *ctx, const struct lys_module *module, unsigned int indent)
+ypr_xmlns(struct ypr_ctx *ctx, const struct lys_module *module, uint16_t indent)
 {
     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);
 }
 
 static void
-ypr_import_xmlns(struct ypr_ctx *ctx, const struct lysp_module *modp, unsigned int indent)
+ypr_import_xmlns(struct ypr_ctx *ctx, const struct lysp_module *modp, uint16_t indent)
 {
     LY_ARRAY_COUNT_TYPE u;
 
@@ -1268,7 +1268,7 @@
 yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
 {
     struct lysp_stmt *childstmt;
-    int flag = stmt->child ? 1 : -1;
+    int8_t flag = stmt->child ? 1 : -1;
 
     /* TODO:
              the extension instance substatements in extension instances (LY_STMT_EXTENSION_INSTANCE)
@@ -1298,13 +1298,14 @@
  */
 static void
 yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
-        struct lysp_ext_instance *ext, int *flag, LY_ARRAY_COUNT_TYPE count)
+        struct lysp_ext_instance *ext, int8_t *flag, LY_ARRAY_COUNT_TYPE count)
 {
     LY_ARRAY_COUNT_TYPE u;
     char *str;
     struct lysp_stmt *stmt;
     const char *argument;
     const char *ext_argument;
+    int8_t inner_flag = 0;
 
     if (!count && ext) {
         count = LY_ARRAY_COUNT(ext);
@@ -1325,7 +1326,7 @@
         }
 
         ypr_close_parent(ctx, flag);
-        int inner_flag = 0;
+        inner_flag = 0;
         argument = NULL;
         ext_argument = NULL;
 
@@ -1451,7 +1452,7 @@
 }
 
 LY_ERR
-yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, int options)
+yin_print_parsed_module(struct ly_out *out, const struct lys_module *module, const struct lysp_module *modp, uint32_t options)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options | LYD_PRINT_FORMAT}, *ctx = &ctx_;
@@ -1513,7 +1514,7 @@
 }
 
 LY_ERR
-yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, int options)
+yin_print_parsed_submodule(struct ly_out *out, const struct lys_module *module, const struct lysp_submodule *submodp, uint32_t options)
 {
     LY_ARRAY_COUNT_TYPE u;
     struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options | LYD_PRINT_FORMAT}, *ctx = &ctx_;
diff --git a/src/set.c b/src/set.c
index 931e4e7..6c82710 100644
--- a/src/set.c
+++ b/src/set.c
@@ -118,7 +118,7 @@
 }
 
 API int
-ly_set_add(struct ly_set *set, void *object, int options)
+ly_set_add(struct ly_set *set, void *object, uint32_t options)
 {
     uint32_t i;
     void **new;
@@ -148,7 +148,7 @@
 }
 
 API int
-ly_set_merge(struct ly_set *trg, struct ly_set *src, int options, void *(*duplicator)(void *obj))
+ly_set_merge(struct ly_set *trg, struct ly_set *src, uint32_t options, void *(*duplicator)(void *obj))
 {
     uint32_t u, c, ret = 0;
     int i;
diff --git a/src/set.h b/src/set.h
index 1074e1f..1afec5a 100644
--- a/src/set.h
+++ b/src/set.h
@@ -91,7 +91,7 @@
  * - #LY_SET_OPT_USEASLIST - do not check for duplicities
  * @return -1 on failure, index of the \p node in the set on success
  */
-int ly_set_add(struct ly_set *set, void *object, int options);
+int ly_set_add(struct ly_set *set, void *object, uint32_t options);
 
 /**
  * @brief Add all objects from \p src to \p trg.
@@ -107,7 +107,7 @@
  * objects as the \p src set.
  * @return -1 on failure, number of objects added into \p trg on success.
  */
-int ly_set_merge(struct ly_set *trg, struct ly_set *src, int options, void *(*duplicator)(void *obj));
+int ly_set_merge(struct ly_set *trg, struct ly_set *src, uint32_t options, void *(*duplicator)(void *obj));
 
 /**
  * @brief Learn whether the set contains the specified object.
diff --git a/src/tree_data.c b/src/tree_data.c
index e2b6efb..a4c4903 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -54,14 +54,14 @@
         struct lyd_node **match);
 
 LY_ERR
-lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int *dynamic, int second, int value_hint,
-        LY_PREFIX_FORMAT format, void *prefix_data, const struct lyd_node *tree)
+lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, uint8_t *dynamic, uint8_t second,
+        uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data, const struct lyd_node *tree)
 {
     LY_ERR ret = LY_SUCCESS;
     struct ly_err_item *err = NULL;
     struct ly_ctx *ctx;
     struct lysc_type *type;
-    int options = value_hint | (second ? LY_TYPE_OPTS_SECOND_CALL : 0) |
+    uint32_t options = value_hint | (second ? LY_TYPE_OPTS_SECOND_CALL : 0) |
             (dynamic && *dynamic ? LY_TYPE_OPTS_DYNAMIC : 0) | (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
     assert(node);
 
@@ -91,14 +91,14 @@
 
 /* similar to lyd_value_parse except can be used just to store the value, hence also does not support a second call */
 LY_ERR
-lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic,
+lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len, uint8_t *dynamic,
         LY_PREFIX_FORMAT format, void *prefix_data)
 {
     LY_ERR ret = LY_SUCCESS;
     struct ly_err_item *err = NULL;
     struct ly_ctx *ctx;
     struct lysc_type *type;
-    int options = LY_TYPE_OPTS_INCOMPLETE_DATA | (dynamic && *dynamic ? LY_TYPE_OPTS_DYNAMIC : 0);
+    uint32_t options = LY_TYPE_OPTS_INCOMPLETE_DATA | (dynamic && *dynamic ? LY_TYPE_OPTS_DYNAMIC : 0);
 
     assert(val && schema && (schema->nodetype & LYD_NODE_TERM));
 
@@ -122,14 +122,14 @@
 }
 
 LY_ERR
-lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, int *dynamic,
-        int second, int value_hint, LY_PREFIX_FORMAT format, void *prefix_data, const struct lysc_node *ctx_snode,
+lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, uint8_t *dynamic,
+        uint8_t second, uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data, const struct lysc_node *ctx_snode,
         const struct lyd_node *tree)
 {
     LY_ERR ret = LY_SUCCESS;
     struct ly_err_item *err = NULL;
     struct lyext_metadata *ant;
-    int options = value_hint | (second ? LY_TYPE_OPTS_SECOND_CALL : 0) |
+    uint32_t options = value_hint | (second ? LY_TYPE_OPTS_SECOND_CALL : 0) |
             (dynamic && *dynamic ? LY_TYPE_OPTS_DYNAMIC : 0) | (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
 
     assert(ctx && meta && ((tree && meta->parent) || ctx_snode));
@@ -205,7 +205,7 @@
     struct ly_err_item *err = NULL;
     struct lysc_type *type;
     struct lyd_value val = {0};
-    int options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
+    uint32_t options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
 
     LY_CHECK_ARG_RET(ctx, node, value, LY_EINVAL);
 
@@ -241,7 +241,7 @@
     struct ly_ctx *ctx;
     struct lysc_type *type;
     struct lyd_value data = {0};
-    int options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
+    uint32_t options = (tree ? 0 : LY_TYPE_OPTS_INCOMPLETE_DATA);
 
     LY_CHECK_ARG_RET(node ? node->schema->module->ctx : NULL, node, value, LY_EINVAL);
 
@@ -298,7 +298,7 @@
 }
 
 API LY_ERR
-lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, int parse_options, int validate_options,
+lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -392,7 +392,7 @@
 }
 
 API LY_ERR
-lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int parse_options, int validate_options,
+lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree)
 {
     LY_ERR ret;
@@ -406,7 +406,7 @@
 }
 
 API LY_ERR
-lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, int parse_options, int validate_options,
+lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree)
 {
     LY_ERR ret;
@@ -420,8 +420,8 @@
 }
 
 API LY_ERR
-lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int parse_options,
-        int validate_options, struct lyd_node **tree)
+lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options,
+        uint32_t validate_options, struct lyd_node **tree)
 {
     LY_ERR ret;
     struct ly_in *in;
@@ -533,7 +533,7 @@
 }
 
 LY_ERR
-lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic, int value_hint,
+lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint,
         LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node)
 {
     LY_ERR ret;
@@ -693,7 +693,7 @@
 
 LY_ERR
 lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len,
-        int *dynamic, int value_hint, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len,
+        uint8_t *dynamic, uint32_t value_hint, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len,
         const char *module_key, size_t module_key_len, struct lyd_node **node)
 {
     struct lyd_node_opaq *opaq;
@@ -1087,7 +1087,7 @@
     struct lyd_node_term *t;
     struct lyd_node *parent;
     struct lyd_value val = {0};
-    int dflt_change, val_change;
+    uint8_t dflt_change, val_change;
 
     LY_CHECK_ARG_RET(NULL, term, term->schema, term->schema->nodetype & LYD_NODE_TERM, LY_EINVAL);
 
@@ -1163,7 +1163,7 @@
     LY_ERR ret = LY_SUCCESS;
     struct lyd_meta *m2;
     struct lyd_value val;
-    int val_change;
+    uint8_t val_change;
 
     LY_CHECK_ARG_RET(NULL, meta, LY_EINVAL);
 
@@ -1197,7 +1197,7 @@
 }
 
 API LY_ERR
-lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, int options,
+lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, uint32_t options,
         struct lyd_node **node)
 {
     return lyd_new_path2(parent, ctx, path, value, 0, options, node, NULL);
@@ -1205,7 +1205,7 @@
 
 API LY_ERR
 lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
-        LYD_ANYDATA_VALUETYPE value_type, int options, struct lyd_node **new_parent, struct lyd_node **new_node)
+        LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent, struct lyd_node **new_node)
 {
     LY_ERR ret = LY_SUCCESS, r;
     struct lyxp_expr *exp = NULL;
@@ -1381,7 +1381,7 @@
 
 LY_ERR
 lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
-        const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when, int impl_opts,
+        const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when, uint32_t impl_opts,
         struct lyd_node **diff)
 {
     LY_ERR ret;
@@ -1491,7 +1491,7 @@
 }
 
 API LY_ERR
-lyd_new_implicit_tree(struct lyd_node *tree, int implicit_options, struct lyd_node **diff)
+lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff)
 {
     struct lyd_node *node;
     LY_ERR ret = LY_SUCCESS;
@@ -1521,7 +1521,7 @@
 }
 
 API LY_ERR
-lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, int implicit_options, struct lyd_node **diff)
+lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff)
 {
     const struct lys_module *mod;
     struct lyd_node *d = NULL;
@@ -1560,7 +1560,7 @@
 }
 
 API LY_ERR
-lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, int implicit_options, struct lyd_node **diff)
+lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options, struct lyd_node **diff)
 {
     struct lyd_node *root, *d = NULL;
     LY_ERR ret = LY_SUCCESS;
@@ -1601,7 +1601,7 @@
 {
     const struct lysc_node *schema, *sparent;
     struct lyd_node *match = NULL;
-    int found;
+    uint8_t found;
 
     assert(new_node);
 
@@ -2118,7 +2118,7 @@
 
 LY_ERR
 lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name,
-        size_t name_len, const char *value, size_t value_len, int *dynamic, int value_hint, LY_PREFIX_FORMAT format,
+        size_t name_len, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint, LY_PREFIX_FORMAT format,
         void *prefix_data, const struct lysc_node *ctx_snode)
 {
     LY_ERR ret;
@@ -2196,7 +2196,7 @@
 
 LY_ERR
 lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name,
-        size_t name_len, const char *value, size_t value_len, int *dynamic, int value_hint, LYD_FORMAT format,
+        size_t name_len, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint, LYD_FORMAT format,
         struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len)
 {
     struct lyd_attr *at, *last;
@@ -2256,7 +2256,7 @@
 }
 
 API LY_ERR
-lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, int options)
+lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options)
 {
     const struct lyd_node *iter1, *iter2;
     struct lyd_node_term *term1, *term2;
@@ -2427,7 +2427,7 @@
 }
 
 API LY_ERR
-lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, int options)
+lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options)
 {
     for ( ; node1 && node2; node1 = node1->next, node2 = node2->next) {
         LY_CHECK_RET(lyd_compare_single(node1, node2, options));
@@ -2474,7 +2474,7 @@
  * @return LY_ERR value
  */
 static LY_ERR
-lyd_dup_r(const struct lyd_node *node, struct lyd_node *parent, struct lyd_node **first, int options,
+lyd_dup_r(const struct lyd_node *node, struct lyd_node *parent, struct lyd_node **first, uint32_t options,
         struct lyd_node **dup_p)
 {
     LY_ERR ret;
@@ -2614,7 +2614,7 @@
         struct lyd_node_inner **local_parent)
 {
     const struct lyd_node_inner *orig_parent, *iter;
-    int repeat = 1;
+    uint8_t repeat = 1;
 
     *dup_parent = NULL;
     *local_parent = NULL;
@@ -2660,7 +2660,7 @@
 }
 
 static LY_ERR
-lyd_dup(const struct lyd_node *node, struct lyd_node_inner *parent, int options, int nosiblings, struct lyd_node **dup)
+lyd_dup(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, uint8_t  nosiblings, struct lyd_node **dup)
 {
     LY_ERR rc;
     const struct lyd_node *orig;          /* original node to be duplicated */
@@ -2706,13 +2706,13 @@
 }
 
 API LY_ERR
-lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup)
+lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup)
 {
     return lyd_dup(node, parent, options, 1, dup);
 }
 
 API LY_ERR
-lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup)
+lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup)
 {
     return lyd_dup(node, parent, options, 0, dup);
 }
@@ -2759,7 +2759,7 @@
  */
 static LY_ERR
 lyd_merge_sibling_r(struct lyd_node **first_trg, struct lyd_node *parent_trg, const struct lyd_node **sibling_src_p,
-        int options)
+        uint16_t options)
 {
     LY_ERR ret;
     const struct lyd_node *child_src, *tmp, *sibling_src;
@@ -2828,10 +2828,10 @@
 }
 
 static LY_ERR
-lyd_merge(struct lyd_node **target, const struct lyd_node *source, int options, int nosiblings)
+lyd_merge(struct lyd_node **target, const struct lyd_node *source, uint16_t options, uint8_t nosiblings)
 {
     const struct lyd_node *sibling_src, *tmp;
-    int first;
+    uint8_t first;
 
     LY_CHECK_ARG_RET(NULL, target, LY_EINVAL);
 
@@ -2867,19 +2867,19 @@
 }
 
 API LY_ERR
-lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, int options)
+lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options)
 {
     return lyd_merge(target, source, options, 1);
 }
 
 API LY_ERR
-lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, int options)
+lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options)
 {
     return lyd_merge(target, source, options, 0);
 }
 
 static LY_ERR
-lyd_path_str_enlarge(char **buffer, size_t *buflen, size_t reqlen, int is_static)
+lyd_path_str_enlarge(char **buffer, size_t *buflen, size_t reqlen, uint8_t is_static)
 {
     /* ending \0 */
     ++reqlen;
@@ -2901,7 +2901,7 @@
 }
 
 LY_ERR
-lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static)
+lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, uint8_t is_static)
 {
     const struct lyd_node *key;
     size_t len;
@@ -2934,7 +2934,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-lyd_path_leaflist_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static)
+lyd_path_leaflist_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, uint8_t is_static)
 {
     size_t len;
     const char *val;
@@ -2964,11 +2964,11 @@
  * @return LY_ERR
  */
 static LY_ERR
-lyd_path_position_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static)
+lyd_path_position_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, uint8_t is_static)
 {
     const struct lyd_node *first, *iter;
     size_t len;
-    int pos;
+    uint64_t pos;
     char *val = NULL;
     LY_ERR rc;
 
@@ -2983,7 +2983,7 @@
             ++pos;
         }
     }
-    if (asprintf(&val, "%d", pos) == -1) {
+    if (asprintf(&val, "%" PRIu64, pos) == -1) {
         return LY_EMEM;
     }
 
@@ -3003,7 +3003,8 @@
 API char *
 lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen)
 {
-    int is_static = 0, i, depth;
+    uint8_t is_static = 0;
+    uint32_t i, depth;
     size_t bufused = 0, len;
     const struct lyd_node *iter;
     const struct lys_module *mod;
@@ -3191,8 +3192,8 @@
     return LY_SUCCESS;
 }
 
-static int
-lyd_hash_table_schema_val_equal(void *val1_p, void *val2_p, int UNUSED(mod), void *UNUSED(cb_data))
+static uint8_t
+lyd_hash_table_schema_val_equal(void *val1_p, void *val2_p, uint8_t UNUSED(mod), void *UNUSED(cb_data))
 {
     struct lysc_node *val1;
     struct lyd_node *val2;
diff --git a/src/tree_data.h b/src/tree_data.h
index c72ce2e..e5d75d3 100644
--- a/src/tree_data.h
+++ b/src/tree_data.h
@@ -89,7 +89,7 @@
  * @param ELEM Iterator intended for use in the block.
  */
 #define LYD_TREE_DFS_BEGIN(START, ELEM) \
-    { int LYD_TREE_DFS_continue = 0; struct lyd_node *LYD_TREE_DFS_next; \
+    { uint8_t LYD_TREE_DFS_continue = 0; struct lyd_node *LYD_TREE_DFS_next; \
     for ((ELEM) = (LYD_TREE_DFS_next) = (struct lyd_node *)(START); \
          (ELEM); \
          (ELEM) = (LYD_TREE_DFS_next), LYD_TREE_DFS_continue = 0)
@@ -195,7 +195,7 @@
                                       whether a value is valid for the specific format or not on later validations
                                       (instance-identifier in XML looks different than in JSON). */
     void *prefix_data;           /**< Format-specific data for prefix resolution (see ::ly_resolve_prefix) */
-    int parser_hint;             /**< Hint options from the parser */
+    uint32_t parser_hint;        /**< Hint options from the parser */
 };
 
 /**
@@ -285,7 +285,7 @@
     const char *value;
 
     LYD_FORMAT format;              /**< format of the prefixes, only LYD_XML and LYD_JSON values can appear at this place */
-    int hint;                       /**< additional information about from the data source, see the [hints list](@ref lydopaqhints) */
+    uint32_t hint;                  /**< additional information about from the data source, see the [hints list](@ref lydopaqhints) */
     struct ly_prefix prefix;        /**< name prefix, it is stored because they are a real pain to generate properly */
 
 };
@@ -470,7 +470,7 @@
     struct ly_prefix prefix;        /**< name prefix */
     struct ly_prefix *val_prefs;    /**< list of prefixes in the value ([sized array](@ref sizedarrays)) */
     const char *value;              /**< original value */
-    int hint;                       /**< additional information about from the data source, see the [hints list](@ref lydopaqhints) */
+    uint32_t hint;                  /**< additional information about from the data source, see the [hints list](@ref lydopaqhints) */
     const struct ly_ctx *ctx;       /**< libyang context */
 };
 
@@ -491,7 +491,7 @@
  * @param[in] options Bitmask of options, see @ref
  * @return Pointer to the first child node (if any) of the \p node.
  */
-struct lyd_node *lyd_node_children(const struct lyd_node *node, int options);
+struct lyd_node *lyd_node_children(const struct lyd_node *node, uint32_t options);
 
 /**
  * @brief Get the owner module of the data node. It is the module of the top-level schema node. Generally,
@@ -673,7 +673,7 @@
  * @return LY_ERR value.
  */
 LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
-        int options, struct lyd_node **node);
+        uint32_t options, struct lyd_node **node);
 
 /**
  * @brief Create a new node in the data tree based on a path. All node types can be created.
@@ -692,7 +692,7 @@
  * @return LY_ERR value.
  */
 LY_ERR lyd_new_path_any(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
-        LYD_ANYDATA_VALUETYPE value_type, int options, struct lyd_node **node);
+        LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node);
 
 /**
  * @brief Create a new node in the data tree based on a path. All node types can be created.
@@ -712,7 +712,7 @@
  * @return LY_ERR value.
  */
 LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
-        LYD_ANYDATA_VALUETYPE value_type, int options, struct lyd_node **new_parent, struct lyd_node **new_node);
+        LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent, struct lyd_node **new_node);
 
 /**
  * @defgroup implicitoptions Implicit node creation options
@@ -741,7 +741,7 @@
  * @param[out] diff Optional diff with any created nodes.
  * @return LY_ERR value.
  */
-LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, int implicit_options, struct lyd_node **diff);
+LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff);
 
 /**
  * @brief Add any missing implicit nodes.
@@ -752,7 +752,7 @@
  * @param[out] diff Optional diff with any created nodes.
  * @return LY_ERR value.
  */
-LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, int implicit_options, struct lyd_node **diff);
+LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff);
 
 /**
  * @brief Add any missing implicit nodes of one module.
@@ -763,7 +763,7 @@
  * @param[out] diff Optional diff with any created nodes.
  * @return LY_ERR value.
  */
-LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, int implicit_options,
+LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options,
         struct lyd_node **diff);
 
 /**
@@ -969,7 +969,7 @@
  * @return LY_SUCCESS if the nodes are equivalent.
  * @return LY_ENOT if the nodes are not equivalent.
  */
-LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, int options);
+LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
 
 /**
  * @brief Compare 2 lists of siblings if they are equivalent.
@@ -980,7 +980,7 @@
  * @return LY_SUCCESS if all the siblings are equivalent.
  * @return LY_ENOT if the siblings are not equivalent.
  */
-LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, int options);
+LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
 
 /**
  * @brief Compare 2 metadata.
@@ -1026,7 +1026,7 @@
  * node(s) (when LYD_DUP_WITH_PARENTS used), the first duplicated node is still returned.
  * @return LY_ERR value.
  */
-LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup);
+LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
 
 /**
  * @brief Create a copy of the specified data tree \p node with any following siblings. Schema references are kept the same.
@@ -1040,7 +1040,7 @@
  * node(s) (when LYD_DUP_WITH_PARENTS used), the first duplicated node is still returned.
  * @return LY_ERR value.
  */
-LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, int options, struct lyd_node **dup);
+LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
 
 /**
  * @brief Create a copy of the metadata.
@@ -1079,7 +1079,7 @@
  * @return LY_SUCCESS on success,
  * @return LY_ERR value on error.
  */
-LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, int options);
+LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
 
 /**
  * @brief Merge the source data tree with any following siblings into the target data tree. Merge may not be
@@ -1092,7 +1092,7 @@
  * @return LY_SUCCESS on success,
  * @return LY_ERR value on error.
  */
-LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, int options);
+LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
 
 /**
  * @defgroup diffoptions Data diff options.
@@ -1136,7 +1136,7 @@
  * @return LY_SUCCESS on success,
  * @return LY_ERR on error.
  */
-LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff);
+LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
 
 /**
  * @brief Learn the differences between 2 data trees including all the following siblings.
@@ -1148,7 +1148,7 @@
  * @return LY_SUCCESS on success,
  * @return LY_ERR on error.
  */
-LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, int options, struct lyd_node **diff);
+LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
 
 /**
  * @brief Callback for diff nodes.
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index 388271b..7c0a52a 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -23,7 +23,7 @@
 #include "plugins_types.h"
 
 static void
-lyd_free_meta(struct lyd_meta *meta, int siblings)
+lyd_free_meta(struct lyd_meta *meta, uint8_t siblings)
 {
     struct lyd_meta *iter;
 
@@ -77,7 +77,7 @@
 }
 
 static void
-ly_free_attr(const struct ly_ctx *ctx, struct lyd_attr *attr, int siblings)
+ly_free_attr(const struct ly_ctx *ctx, struct lyd_attr *attr, uint8_t siblings)
 {
     struct lyd_attr *iter;
     LY_ARRAY_COUNT_TYPE u;
@@ -157,7 +157,7 @@
  * @param[in] top Recursion flag to unlink the root of the subtree being freed.
  */
 static void
-lyd_free_subtree(struct lyd_node *node, int top)
+lyd_free_subtree(struct lyd_node *node, uint8_t top)
 {
     struct lyd_node *iter, *next;
     struct lyd_node *children;
@@ -222,7 +222,7 @@
 }
 
 static void
-lyd_free_(struct lyd_node *node, int top)
+lyd_free_(struct lyd_node *node, uint8_t top)
 {
     struct lyd_node *iter, *next;
 
diff --git a/src/tree_data_hash.c b/src/tree_data_hash.c
index e299b7d..177a394 100644
--- a/src/tree_data_hash.c
+++ b/src/tree_data_hash.c
@@ -83,8 +83,8 @@
     return LY_SUCCESS;
 }
 
-static int
-lyd_hash_table_val_equal(void *val1_p, void *val2_p, int mod, void *UNUSED(cb_data))
+static uint8_t
+lyd_hash_table_val_equal(void *val1_p, void *val2_p, uint8_t mod, void *UNUSED(cb_data))
 {
     struct lyd_node *val1, *val2;
 
@@ -120,7 +120,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyd_insert_hash_add(struct hash_table *ht, struct lyd_node *node, int empty_ht)
+lyd_insert_hash_add(struct hash_table *ht, struct lyd_node *node, uint8_t empty_ht)
 {
     uint32_t hash;
 
diff --git a/src/tree_data_helpers.c b/src/tree_data_helpers.c
index faf1263..86b0c64 100644
--- a/src/tree_data_helpers.c
+++ b/src/tree_data_helpers.c
@@ -83,7 +83,7 @@
 }
 
 API struct lyd_node *
-lyd_node_children(const struct lyd_node *node, int options)
+lyd_node_children(const struct lyd_node *node, uint32_t options)
 {
     struct lyd_node **children, *child;
 
@@ -199,7 +199,7 @@
 }
 
 void
-lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options)
+lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, uint32_t options)
 {
     struct lyd_meta *meta2, *prev_meta = NULL;
 
@@ -242,7 +242,6 @@
 lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type)
 {
     struct lyd_node_any *t;
-    int len;
 
     assert(trg->schema->nodetype & LYS_ANYDATA);
 
@@ -286,7 +285,7 @@
         break;
     case LYD_ANYDATA_LYB:
         if (value->mem) {
-            len = lyd_lyb_data_length(value->mem);
+            int len = lyd_lyb_data_length(value->mem);
             LY_CHECK_RET(len == -1, LY_EINVAL);
             t->value.mem = malloc(len);
             LY_CHECK_ERR_RET(!t->value.mem, LOGMEM(LYD_CTX(trg)), LY_EMEM);
@@ -302,7 +301,6 @@
 lyb_hash(struct lysc_node *sibling, uint8_t collision_id)
 {
     const struct lys_module *mod;
-    int ext_len;
     uint32_t full_hash;
     LYB_HASH hash;
 
@@ -315,6 +313,8 @@
     full_hash = dict_hash_multi(0, mod->name, strlen(mod->name));
     full_hash = dict_hash_multi(full_hash, sibling->name, strlen(sibling->name));
     if (collision_id) {
+        size_t ext_len;
+
         if (collision_id > strlen(mod->name)) {
             /* fine, we will not hash more bytes, just use more bits from the hash than previously */
             ext_len = strlen(mod->name);
@@ -339,7 +339,7 @@
     return hash;
 }
 
-int
+uint8_t
 lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models)
 {
     LY_ARRAY_COUNT_TYPE u;
diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h
index f7c0540..07c4134 100644
--- a/src/tree_data_internal.h
+++ b/src/tree_data_internal.h
@@ -48,8 +48,9 @@
  * @param[in] models Modules in a sized array.
  * @return non-zero if the module was found,
  * @return 0 if not found.
+ * @return 1 if found.
  */
-int lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
+uint8_t lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models);
 
 /**
  * @brief Check whether a node to be deleted is the first top-level sibling.
@@ -102,7 +103,7 @@
  * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
  * @return LY_ERR value if an error occurred.
  */
-LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic, int value_hint,
+LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint,
         LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node);
 
 /**
@@ -181,7 +182,7 @@
  * @return LY_ERR value if an error occurred.
  */
 LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len,
-        int *dynamic, int value_hint, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix,
+        uint8_t *dynamic, uint32_t value_hint, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix,
         size_t pref_len, const char *module_key, size_t module_key_len, struct lyd_node **node);
 
 /**
@@ -199,7 +200,7 @@
  */
 LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent,
         const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when,
-        int impl_opts, struct lyd_node **diff);
+        uint32_t impl_opts, struct lyd_node **diff);
 
 /**
  * @brief Find the next node, before which to insert the new node.
@@ -248,7 +249,7 @@
  * @return LY_ERR value if an error occurred.
  */
 LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name,
-        size_t name_len, const char *value, size_t value_len, int *dynamic, int value_hint,
+        size_t name_len, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint,
         LY_PREFIX_FORMAT format, void *prefix_data, const struct lysc_node *ctx_snode);
 
 /**
@@ -281,7 +282,7 @@
  * @return LY_ERR value if an error occurred.
  */
 LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name,
-        size_t name_len, const char *value, size_t value_len, int *dynamic, int value_hint, LYD_FORMAT format,
+        size_t name_len, const char *value, size_t value_len, uint8_t *dynamic, uint32_t value_hint, LYD_FORMAT format,
         struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len);
 
 /**
@@ -315,12 +316,12 @@
  * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation.
  * @return LY_ERR value if an error occurred.
  */
-LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int *dynamic, int second, int value_hint,
-        LY_PREFIX_FORMAT format, void *prefix_data, const struct lyd_node *tree);
+LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, uint8_t *dynamic, uint8_t second,
+        uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data, const struct lyd_node *tree);
 
 /* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */
 LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len,
-        int *dynamic, LY_PREFIX_FORMAT format, void *prefix_data);
+        uint8_t *dynamic, LY_PREFIX_FORMAT format, void *prefix_data);
 
 /**
  * @brief Validate, canonize and store the given @p value into the metadata according to the annotation type's rules.
@@ -343,7 +344,7 @@
  * @return LY_ERR value if an error occurred.
  */
 LY_ERR lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len,
-        int *dynamic, int second, int value_hint, LY_PREFIX_FORMAT format, void *prefix_data,
+        uint8_t *dynamic, uint8_t second, uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data,
         const struct lysc_node *ctx_snode, const struct lyd_node *tree);
 
 /* generic function lys_value_validate */
@@ -361,7 +362,7 @@
  * @param[out] lydctx_p Data parser context to finish validation.
  * @return LY_ERR value.
  */
-LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p);
 
 /**
@@ -418,7 +419,7 @@
  * @param[out] lydctx_p Data parser context to finish validation.
  * @return LY_ERR value.
  */
-LY_ERR lyd_parse_json_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+LY_ERR lyd_parse_json_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p);
 
 /**
@@ -474,7 +475,7 @@
  * @param[out] lydctx_p Data parser context to finish validation.
  * @return LY_ERR value.
  */
-LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, int parse_options, int validate_options,
+LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options,
         struct lyd_node **tree_p, struct lyd_ctx **lydctx_p);
 
 /**
@@ -583,7 +584,7 @@
  * @param[in,out] meta Node metadata, may be removed from.
  * @param[in] options Parse options.
  */
-void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, int options);
+void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, uint32_t options);
 
 /**
  * @brief Free value prefixes.
@@ -603,6 +604,6 @@
  * @param[in] is_static Whether buffer is static or can be reallocated.
  * @return LY_ERR
  */
-LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, int is_static);
+LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, uint8_t is_static);
 
 #endif /* LY_TREE_DATA_INTERNAL_H_ */
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 2f4df6e..64d445e 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -40,11 +40,11 @@
 #include "xpath.h"
 
 API const struct lysc_node *
-lys_getnext(const struct lysc_node *last, const struct lysc_node *parent, const struct lysc_module *module, int options)
+lys_getnext(const struct lysc_node *last, const struct lysc_node *parent, const struct lysc_module *module, uint32_t options)
 {
     const struct lysc_node *next = NULL;
     struct lysc_node **snode;
-    int action_flag = 0, notif_flag = 0;
+    uint8_t action_flag = 0, notif_flag = 0;
     const struct lysc_action *actions;
     const struct lysc_notif *notifs;
     LY_ARRAY_COUNT_TYPE u;
@@ -196,7 +196,6 @@
     const char *id = qpath;
     const char *prefix, *name;
     size_t prefix_len, name_len;
-    unsigned int u;
     const struct lysc_node *node = context_node;
     struct lys_module *mod = NULL;
 
@@ -224,7 +223,7 @@
             if (context_node) {
                 mod = lys_module_find_prefix(context_node->module, prefix, prefix_len);
             } else {
-                for (u = 0; u < ctx->list.count; ++u) {
+                for (uint32_t u = 0; u < ctx->list.count; ++u) {
                     if (!ly_strncmp(((struct lys_module *)ctx->list.objs[u])->name, prefix, prefix_len)) {
                         struct lys_module *m = (struct lys_module *)ctx->list.objs[u];
                         if (mod) {
@@ -259,7 +258,7 @@
 
 API const struct lysc_node *
 lys_find_child(const struct lysc_node *parent, const struct lys_module *module, const char *name, size_t name_len,
-        uint16_t nodetype, int options)
+        uint16_t nodetype, uint32_t options)
 {
     const struct lysc_node *node = NULL;
 
@@ -290,7 +289,7 @@
 }
 
 API LY_ERR
-lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set)
+lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyxp_set xp_set;
@@ -334,7 +333,7 @@
 }
 
 API LY_ERR
-lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set)
+lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set)
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyxp_set xp_set;
@@ -467,20 +466,18 @@
 }
 
 uint8_t
-lysc_iff_getop(uint8_t *list, int pos)
+lysc_iff_getop(uint8_t *list, size_t pos)
 {
     uint8_t *item;
     uint8_t mask = 3, result;
 
-    assert(pos >= 0);
-
     item = &list[pos / 4];
     result = (*item) & (mask << 2 * (pos % 4));
     return result >> 2 * (pos % 4);
 }
 
 static LY_ERR
-lysc_iffeature_value_(const struct lysc_iffeature *iff, int *index_e, int *index_f)
+lysc_iffeature_value_(const struct lysc_iffeature *iff, size_t *index_e, size_t *index_f)
 {
     uint8_t op;
     LY_ERR a, b;
@@ -520,7 +517,7 @@
 API LY_ERR
 lysc_iffeature_value(const struct lysc_iffeature *iff)
 {
-    int index_e = 0, index_f = 0;
+    size_t index_e = 0, index_f = 0;
 
     LY_CHECK_ARG_RET(NULL, iff, -1);
 
@@ -545,9 +542,9 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lys_feature_change(const struct lys_module *mod, const char *name, int value, int skip_checks)
+lys_feature_change(const struct lys_module *mod, const char *name, uint8_t value, uint8_t skip_checks)
 {
-    int all = 0;
+    uint8_t all = 0;
     LY_ARRAY_COUNT_TYPE u, disabled_count;
     uint32_t changed_count;
     struct lysc_feature *f, **df;
@@ -764,7 +761,7 @@
 }
 
 API const struct lysc_node *
-lysc_node_is_disabled(const struct lysc_node *node, int recursive)
+lysc_node_is_disabled(const struct lysc_node *node, uint8_t recursive)
 {
     LY_ARRAY_COUNT_TYPE u;
 
@@ -962,10 +959,9 @@
 }
 
 LY_ERR
-lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, int implement,
-        LY_ERR (*custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod,
-                                            struct lysp_submodule *submod, void *data), void *check_data,
-        struct lys_module **module)
+lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, uint8_t implement,
+        LY_ERR (*custom_check)(const struct ly_ctx *ctx, struct lysp_module *mod, struct lysp_submodule *submod, void *data),
+        void *check_data, struct lys_module **module)
 {
     struct lys_module *mod = NULL, *latest, *mod_dup;
     LY_ERR ret;
@@ -1230,11 +1226,12 @@
 }
 
 API LY_ERR
-lys_search_localfile(const char * const *searchpaths, int cwd, const char *name, const char *revision,
+lys_search_localfile(const char * const *searchpaths, uint8_t cwd, const char *name, const char *revision,
         char **localfile, LYS_INFORMAT *format)
 {
+    LY_ERR ret = LY_EMEM;
     size_t len, flen, match_len = 0, dir_len;
-    int i, implicit_cwd = 0, ret = EXIT_FAILURE;
+    uint8_t implicit_cwd = 0;
     char *wd, *wn = NULL;
     DIR *dir = NULL;
     struct dirent *file;
@@ -1249,8 +1246,7 @@
      * and the current working directory */
     dirs = ly_set_new();
     if (!dirs) {
-        LOGMEM(NULL);
-        return EXIT_FAILURE;
+        LOGMEM_RET(NULL);
     }
 
     len = strlen(name);
@@ -1269,7 +1265,7 @@
         }
     }
     if (searchpaths) {
-        for (i = 0; searchpaths[i]; i++) {
+        for (uint64_t i = 0; searchpaths[i]; i++) {
             /* check for duplicities with the implicit current working directory */
             if (implicit_cwd && !strcmp(dirs->objs[0], searchpaths[i])) {
                 implicit_cwd = 0;
@@ -1407,7 +1403,7 @@
     if (format) {
         (*format) = match_format;
     }
-    ret = EXIT_SUCCESS;
+    ret = LY_SUCCESS;
 
 cleanup:
     free(wn);
diff --git a/src/tree_schema.h b/src/tree_schema.h
index 9d6b36a..58fc6cd 100644
--- a/src/tree_schema.h
+++ b/src/tree_schema.h
@@ -69,7 +69,7 @@
  * @param ELEM Iterator intended for use in the block.
  */
 #define LYSC_TREE_DFS_BEGIN(START, ELEM) \
-    { int LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
+    { uint8_t LYSC_TREE_DFS_continue = 0; struct lysc_node *LYSC_TREE_DFS_next; \
     for ((ELEM) = (LYSC_TREE_DFS_next) = (struct lysc_node*)(START); \
          (ELEM); \
          (ELEM) = (LYSC_TREE_DFS_next), LYSC_TREE_DFS_continue = 0)
@@ -1725,8 +1725,9 @@
  * @param[in] node Node to examine.
  * @return non-zero if it is,
  * @return 0 if not.
+ * @return 1 if the @p node is user-ordered
  */
-int lysc_is_userordered(const struct lysc_node *schema);
+uint8_t lysc_is_userordered(const struct lysc_node *schema);
 
 /**
  * @brief Set a schema private pointer to a user pointer.
@@ -1774,7 +1775,7 @@
  * @return LY_SUCCESS on success, @p set is returned.
  * @return LY_ERR value if an error occurred.
  */
-LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set);
+LY_ERR lys_atomize_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
 
 /**
  * @brief Evaluate an \p xpath expression on schema nodes.
@@ -1787,7 +1788,7 @@
  * @return LY_SUCCESS on success, @p set is returned.
  * @return LY_ERR value if an error occurred.
  */
-LY_ERR lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, int options, struct ly_set **set);
+LY_ERR lys_find_xpath(const struct lysc_node *ctx_node, const char *xpath, uint32_t options, struct ly_set **set);
 
 /**
  * @brief Types of the different schema paths.
@@ -1945,7 +1946,7 @@
  * @return Next schema tree node that can be instantiated in a data tree, NULL in case there is no such element.
  */
 const struct lysc_node *lys_getnext(const struct lysc_node *last, const struct lysc_node *parent,
-        const struct lysc_module *module, int options);
+        const struct lysc_module *module, uint32_t options);
 
 /**
  * @defgroup sgetnextflags lys_getnext() flags
@@ -1974,7 +1975,7 @@
  * @return Found node if any.
  */
 const struct lysc_node *lys_find_child(const struct lysc_node *parent, const struct lys_module *module,
-        const char *name, size_t name_len, uint16_t nodetype, int options);
+        const char *name, size_t name_len, uint16_t nodetype, uint32_t options);
 
 /**
  * @brief Get schema node specified by the schema path.
@@ -2015,7 +2016,7 @@
  * @return NULL if enabled,
  * @return pointer to the node with the unsatisfied (disabled) if-feature expression.
  */
-const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, int recursive);
+const struct lysc_node *lysc_node_is_disabled(const struct lysc_node *node, uint8_t recursive);
 
 /**
  * @brief Set a schema private pointer to a user pointer.
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index cae0cd0..397c372 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -238,7 +238,7 @@
 lysc_update_path(struct lysc_ctx *ctx, struct lysc_node *parent, const char *name)
 {
     int len;
-    int nextlevel = 0; /* 0 - no starttag, 1 - '/' starttag, 2 - '=' starttag + '}' endtag */
+    uint8_t nextlevel = 0; /* 0 - no starttag, 1 - '/' starttag, 2 - '=' starttag + '}' endtag */
 
     if (!name) {
         /* removing last path segment */
@@ -282,7 +282,7 @@
         } else {
             len = snprintf(&ctx->path[ctx->path_len], LYSC_CTX_BUFSIZE - ctx->path_len, "='%s'}", name);
         }
-        if (len >= LYSC_CTX_BUFSIZE - ctx->path_len) {
+        if (len >= LYSC_CTX_BUFSIZE - (int)ctx->path_len) {
             /* output truncated */
             ctx->path_len = LYSC_CTX_BUFSIZE - 1;
         } else {
@@ -370,9 +370,9 @@
  * @brief Stack for processing if-feature expressions.
  */
 struct iff_stack {
-    int size;      /**< number of items in the stack */
-    int index;     /**< first empty item */
-    uint8_t *stack;/**< stack - array of @ref ifftokens to create the if-feature expression in prefix format */
+    size_t size;    /**< number of items in the stack */
+    size_t index;   /**< first empty item */
+    uint8_t *stack; /**< stack - array of @ref ifftokens to create the if-feature expression in prefix format */
 };
 
 /**
@@ -427,12 +427,11 @@
  * @param[in] pos Position (0-based) where to store the given @p op.
  */
 static void
-iff_setop(uint8_t *list, uint8_t op, int pos)
+iff_setop(uint8_t *list, uint8_t op, size_t pos)
 {
     uint8_t *item;
     uint8_t mask = 3;
 
-    assert(pos >= 0);
     assert(op <= 3); /* max 2 bits */
 
     item = &list[pos / 4];
@@ -695,10 +694,11 @@
 static LY_ERR
 lys_compile_iffeature(struct lysc_ctx *ctx, const char **value, struct lysc_iffeature *iff)
 {
+    LY_ERR rc = LY_SUCCESS;
     const char *c = *value;
-    int r, rc = EXIT_FAILURE;
-    int i, j, last_not, checkversion = 0;
-    unsigned int f_size = 0, expr_size = 0, f_exp = 1;
+    int64_t i, j;
+    int8_t op_len, last_not = 0, checkversion = 0;
+    LY_ARRAY_COUNT_TYPE f_size = 0, expr_size = 0, f_exp = 1;
     uint8_t op;
     struct iff_stack stack = {0, 0, NULL};
     struct lysc_feature *f;
@@ -706,7 +706,7 @@
     assert(c);
 
     /* pre-parse the expression to get sizes for arrays, also do some syntax checks of the expression */
-    for (i = j = last_not = 0; c[i]; i++) {
+    for (i = j = 0; c[i]; i++) {
         if (c[i] == '(') {
             j++;
             checkversion = 1;
@@ -719,14 +719,14 @@
             continue;
         }
 
-        if (!strncmp(&c[i], "not", r = 3) || !strncmp(&c[i], "and", r = 3) || !strncmp(&c[i], "or", r = 2)) {
-            int sp;
-            for (sp = 0; c[i + r + sp] && isspace(c[i + r + sp]); sp++);
-            if (c[i + r + sp] == '\0') {
+        if (!strncmp(&c[i], "not", op_len = 3) || !strncmp(&c[i], "and", op_len = 3) || !strncmp(&c[i], "or", op_len = 2)) {
+            uint64_t spaces;
+            for (spaces = 0; c[i + op_len + spaces] && isspace(c[i + op_len + spaces]); spaces++);
+            if (c[i + op_len + spaces] == '\0') {
                 LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SYNTAX_YANG,
                        "Invalid value \"%s\" of if-feature - unexpected end of expression.", *value);
                 return LY_EVALID;
-            } else if (!isspace(c[i + r])) {
+            } else if (!isspace(c[i + op_len])) {
                 /* feature name starting with the not/and/or */
                 last_not = 0;
                 f_size++;
@@ -741,7 +741,7 @@
             } else { /* and, or */
                 if (f_exp != f_size) {
                     LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SYNTAX_YANG,
-                           "Invalid value \"%s\" of if-feature - missing feature/expression before \"%.*s\" operation.", *value, r, &c[i]);
+                           "Invalid value \"%s\" of if-feature - missing feature/expression before \"%.*s\" operation.", *value, op_len, &c[i]);
                     return LY_EVALID;
                 }
                 f_exp++;
@@ -749,7 +749,7 @@
                 /* not a not operation */
                 last_not = 0;
             }
-            i += r;
+            i += op_len;
         } else {
             f_size++;
             last_not = 0;
@@ -791,7 +791,7 @@
     LY_ARRAY_CREATE_RET(ctx->ctx, iff->features, f_size, LY_EMEM);
     iff->expr = calloc((j = (expr_size / 4) + ((expr_size % 4) ? 1 : 0)), sizeof *iff->expr);
     stack.stack = malloc(expr_size * sizeof *stack.stack);
-    LY_CHECK_ERR_GOTO(!stack.stack || !iff->expr, LOGMEM(ctx->ctx), error);
+    LY_CHECK_ERR_GOTO(!stack.stack || !iff->expr, LOGMEM(ctx->ctx); rc = LY_EMEM, error);
 
     stack.size = expr_size;
     f_size--; expr_size--; /* used as indexes from now */
@@ -1494,7 +1494,7 @@
  * @return LY_SUCCESS or LY_EEXIST for invalid order.
  */
 static LY_ERR
-range_part_check_ascendancy(int unsigned_value, int max, int64_t value, int64_t prev_value)
+range_part_check_ascendancy(uint8_t unsigned_value, uint8_t max, int64_t value, int64_t prev_value)
 {
     if (unsigned_value) {
         if ((max && (uint64_t)prev_value > (uint64_t)value) || (!max && (uint64_t)prev_value >= (uint64_t)value)) {
@@ -1525,8 +1525,8 @@
  * frdigits value), LY_EMEM.
  */
 static LY_ERR
-range_part_minmax(struct lysc_ctx *ctx, struct lysc_range_part *part, int max, int64_t prev, LY_DATA_TYPE basetype,
-        int first, int length_restr, uint8_t frdigits, struct lysc_range *base_range, const char **value)
+range_part_minmax(struct lysc_ctx *ctx, struct lysc_range_part *part, uint8_t max, int64_t prev, LY_DATA_TYPE basetype,
+        uint8_t first, uint8_t length_restr, uint8_t frdigits, struct lysc_range *base_range, const char **value)
 {
     LY_ERR ret = LY_SUCCESS;
     char *valcopy = NULL;
@@ -1688,13 +1688,13 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lys_compile_type_range(struct lysc_ctx *ctx, struct lysp_restr *range_p, LY_DATA_TYPE basetype, int length_restr,
+lys_compile_type_range(struct lysc_ctx *ctx, struct lysp_restr *range_p, LY_DATA_TYPE basetype, uint8_t length_restr,
         uint8_t frdigits, struct lysc_range *base_range, struct lysc_range **range)
 {
     LY_ERR ret = LY_EVALID;
     const char *expr;
     struct lysc_range_part *parts = NULL, *part;
-    int range_expected = 0, uns;
+    uint8_t range_expected = 0, uns;
     LY_ARRAY_COUNT_TYPE parts_done = 0, u, v;
 
     assert(range);
@@ -1927,7 +1927,7 @@
 LY_ERR
 lys_compile_type_pattern_check(struct ly_ctx *ctx, const char *log_path, const char *pattern, pcre2_code **code)
 {
-    int idx, idx2, start, end, size, brack;
+    size_t idx, idx2, start, end, size, brack;
     char *perl_regex, *ptr;
     int err_code;
     const char *orig_ptr;
@@ -2395,9 +2395,9 @@
  */
 LY_ERR
 lys_path_token(const char **path, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len,
-        int *parent_times, int *has_predicate)
+        int32_t *parent_times, uint8_t *has_predicate)
 {
-    int par_times = 0;
+    int32_t par_times = 0;
 
     assert(path && *path);
     assert(parent_times);
@@ -2467,7 +2467,8 @@
 {
     LY_ERR ret = LY_EVALID;
     const struct lysc_node *iter;
-    LY_ARRAY_COUNT_TYPE u, v, count;
+    LY_ARRAY_COUNT_TYPE u, v;
+    uint32_t count;
     struct ly_set features = {0};
 
     for (iter = refnode; iter; iter = iter->parent) {
@@ -2489,7 +2490,7 @@
         if (iter->iffeatures) {
             LY_ARRAY_FOR(iter->iffeatures, u) {
                 LY_ARRAY_FOR(iter->iffeatures[u].features, v) {
-                    if ((unsigned int)ly_set_add(&features, iter->iffeatures[u].features[v], 0) >= count) {
+                    if ((uint32_t)ly_set_add(&features, iter->iffeatures[u].features[v], 0) >= count) {
                         /* new feature was added (or LY_EMEM) */
                         goto cleanup;
                     }
@@ -2917,8 +2918,7 @@
         struct lysc_type **type, const char **units, const char **dflt, struct lys_module **dflt_mod)
 {
     LY_ERR ret = LY_SUCCESS;
-    unsigned int u;
-    int dummyloops = 0;
+    uint8_t dummyloops = 0;
     struct type_context {
         const struct lysp_tpdf *tpdf;
         struct lysp_node *node;
@@ -2981,7 +2981,7 @@
         }
 
         /* circular typedef reference detection */
-        for (u = 0; u < tpdf_chain.count; u++) {
+        for (uint32_t u = 0; u < tpdf_chain.count; u++) {
             /* local part */
             tctx_iter = (struct type_context *)tpdf_chain.objs[u];
             if (tctx_iter->mod == tctx->mod && tctx_iter->node == tctx->node && tctx_iter->tpdf == tctx->tpdf) {
@@ -2992,7 +2992,7 @@
                 goto cleanup;
             }
         }
-        for (u = 0; u < ctx->tpdf_chain.count; u++) {
+        for (uint32_t u = 0; u < ctx->tpdf_chain.count; u++) {
             /* global part for unions corner case */
             tctx_iter = (struct type_context *)ctx->tpdf_chain.objs[u];
             if (tctx_iter->mod == tctx->mod && tctx_iter->node == tctx->node && tctx_iter->tpdf == tctx->tpdf) {
@@ -3075,7 +3075,7 @@
     }
 
     /* get restrictions from the referred typedefs */
-    for (u = tpdf_chain.count - 1; u + 1 > 0; --u) {
+    for (uint32_t u = tpdf_chain.count - 1; u + 1 > 0; --u) {
         tctx = (struct type_context *)tpdf_chain.objs[u];
 
         /* remember the typedef context for circular check */
@@ -3249,8 +3249,8 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lysp_node *child_p;
-    unsigned int u;
-    int opt_prev = ctx->options;
+    LY_ARRAY_COUNT_TYPE u;
+    uint32_t opt_prev = ctx->options;
 
     lysc_update_path(ctx, parent, action_p->name);
 
@@ -3334,8 +3334,8 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lysp_node *child_p;
-    unsigned int u;
-    int opt_prev = ctx->options;
+    LY_ARRAY_COUNT_TYPE u;
+    uint32_t opt_prev = ctx->options;
 
     lysc_update_path(ctx, parent, notif_p->name);
 
@@ -3597,7 +3597,7 @@
     const char *keystr, *delim;
     size_t len;
     LY_ARRAY_COUNT_TYPE v;
-    int config;
+    int8_t config; /* -1 - not yet seen; 0 - LYS_CONFIG_R; 1 - LYS_CONFIG_W */
     uint16_t flags;
 
     for (v = 0; v < LY_ARRAY_COUNT(uniques); ++v) {
@@ -3685,7 +3685,7 @@
     struct lysp_node *child_p;
     struct lysc_node_leaf *key, *prev_key = NULL;
     size_t len;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     const char *keystr, *delim;
     LY_ERR ret = LY_SUCCESS;
 
@@ -3998,7 +3998,7 @@
 {
     struct lysp_node_anydata *any_p = (struct lysp_node_anydata *)node_p;
     struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     LY_ERR ret = LY_SUCCESS;
 
     COMPILE_ARRAY_GOTO(ctx, any_p->musts, any->musts, u, lys_compile_must, ret, done);
@@ -4103,7 +4103,7 @@
     struct lysc_node *iter;
     struct lysc_node_case *cs = NULL;
     struct lysc_when **when;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     LY_ERR ret;
 
 #define UNIQUE_CHECK(NAME, MOD) \
@@ -4184,7 +4184,7 @@
  */
 static LY_ERR
 lys_compile_change_config(struct lysc_ctx *ctx, struct lysc_node *node, uint16_t config_flag,
-        int inheriting, int refine_flag)
+        uint8_t inheriting, uint8_t refine_flag)
 {
     struct lysc_node *child;
     uint16_t config = config_flag & LYS_CONFIG_MASK;
@@ -4238,8 +4238,8 @@
  * @param[in] add Flag to distinguish adding the mandatory flag (new mandatory children appeared) or removing the flag
  * (mandatory children was removed).
  */
-void
-lys_compile_mandatory_parents(struct lysc_node *parent, int add)
+static void
+lys_compile_mandatory_parents(struct lysc_node *parent, uint8_t add)
 {
     struct lysc_node *iter;
 
@@ -4364,10 +4364,10 @@
     struct lysc_node *node;
     struct lysc_when **when, *when_shared;
     struct lys_module **aug_mod;
-    int allow_mandatory = 0;
+    uint8_t allow_mandatory = 0;
     uint16_t flags = 0;
     LY_ARRAY_COUNT_TYPE u, v;
-    int opt_prev = ctx->options;
+    uint32_t opt_prev = ctx->options;
 
     lysc_update_path(ctx, NULL, "{augment}");
     lysc_update_path(ctx, NULL, aug_p->nodeid);
@@ -4531,7 +4531,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lys_compile_change_mandatory(struct lysc_ctx *ctx, struct lysc_node *node, uint16_t mandatory_flag, int refine_flag)
+lys_compile_change_mandatory(struct lysc_ctx *ctx, struct lysc_node *node, uint16_t mandatory_flag, uint8_t refine_flag)
 {
     if (!(node->nodetype & (LYS_LEAF | LYS_ANYDATA | LYS_ANYXML | LYS_CHOICE))) {
         LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_SEMANTICS,
@@ -4601,7 +4601,7 @@
     struct lysp_grp *grp = NULL;
     LY_ARRAY_COUNT_TYPE u, v;
     uint32_t grp_stack_count;
-    int found;
+    uint8_t found = 0;
     const char *id, *name, *prefix;
     size_t prefix_len, name_len;
     struct lys_module *mod, *mod_old;
@@ -4617,7 +4617,6 @@
     struct lysc_action **actions = NULL;
 
     /* search for the grouping definition */
-    found = 0;
     id = uses_p->name;
     LY_CHECK_RET(ly_parse_nodeid(&id, &prefix, &prefix_len, &name, &name_len), LY_EVALID);
     if (prefix) {
@@ -5120,7 +5119,7 @@
         return LY_EMEM;
     }
     strncpy(ctx->path, path, LYSC_CTX_BUFSIZE - 1);
-    ctx->path_len = (uint16_t)len;
+    ctx->path_len = (uint32_t)len;
     free(path);
 
     lysc_update_path(ctx, NULL, "{grouping}");
@@ -5156,7 +5155,7 @@
     struct lysc_node *node = NULL;
     struct lysc_node_case *cs = NULL;
     struct lysc_when **when;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     LY_ERR (*node_compile_spec)(struct lysc_ctx *, struct lysp_node *, struct lysc_node *);
 
     if (node_p->nodetype != LYS_USES) {
@@ -5354,7 +5353,7 @@
     struct lysc_node *parent, *child, *prev = NULL, *next;
     struct lysc_node_case *cs = NULL;
     struct lysc_module *modc = node->module->compiled;
-    int remove_cs = 0;
+    uint8_t remove_cs = 0;
 
     parent = node->parent;
 
@@ -5485,7 +5484,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lys_apply_deviate_add(struct lysc_ctx *ctx, struct lysc_node *target, int dev_flags, struct lysp_deviate_add *d)
+lys_apply_deviate_add(struct lysc_ctx *ctx, struct lysc_node *target, uint32_t dev_flags, struct lysp_deviate_add *d)
 {
     LY_ERR ret = LY_EVALID;
     struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)target;
@@ -5502,7 +5501,7 @@
 
 #define DEV_CHECK_NONPRESENCE_VALUE(TYPE, COND, MEMBER, PROPERTY, VALUEMEMBER) \
     if (((TYPE)target)->MEMBER && (COND)) { \
-        int dynamic_ = 0; const char *val_; \
+        uint8_t dynamic_ = 0; const char *val_; \
         val_ = ((TYPE)target)->VALUEMEMBER->realtype->plugin->print(((TYPE)target)->VALUEMEMBER, LY_PREF_SCHEMA, \
                                                                              ctx->mod_def, &dynamic_); \
         LOGVAL(ctx->ctx, LY_VLOG_STR, ctx->path, LYVE_REFERENCE, \
@@ -5700,7 +5699,7 @@
 lys_apply_deviate_delete_leaf_dflt(struct lysc_ctx *ctx, struct lysc_node *target, const char *dflt)
 {
     struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)target;
-    int dyn = 0;
+    uint8_t dyn = 0;
     const char *orig_dflt;
     uint32_t i;
 
@@ -5763,7 +5762,7 @@
 lys_apply_deviate_delete_llist_dflts(struct lysc_ctx *ctx, struct lysc_node *target, const char **dflts)
 {
     struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)target;
-    int dyn = 0, found;
+    uint8_t dyn = 0, found;
     const char *orig_dflt, **orig_dflts;
     uint32_t i;
     LY_ARRAY_COUNT_TYPE x, y;
@@ -5864,7 +5863,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lys_apply_deviate_delete(struct lysc_ctx *ctx, struct lysc_node *target, int dev_flags, struct lysp_deviate_del *d)
+lys_apply_deviate_delete(struct lysc_ctx *ctx, struct lysc_node *target, uint32_t dev_flags, struct lysp_deviate_del *d)
 {
     LY_ERR ret = LY_EVALID;
     struct lysc_node_list *list = (struct lysc_node_list *)target;
@@ -6049,7 +6048,7 @@
     struct ly_err_item *err = NULL;
     LY_ARRAY_COUNT_TYPE x;
     const char *dflt;
-    int dyn;
+    uint8_t dyn;
 
     if (target->module != ctx->mod) {
         /* foreign deviation */
@@ -6475,6 +6474,7 @@
         }
         /* insert into the set of targets with duplicity detection */
         i = ly_set_add(&targets, target, 0);
+        LY_CHECK_ERR_GOTO(i < 0, ret = LY_EMEM, cleanup);
         if (!devs[i]) {
             /* new record */
             devs[i] = calloc(1, sizeof **devs);
@@ -6549,7 +6549,7 @@
 LY_ERR
 lys_compile_submodule(struct lysc_ctx *ctx, struct lysp_include *inc)
 {
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     LY_ERR ret = LY_SUCCESS;
     /* shortcuts */
     struct lysp_submodule *submod = inc->submodule;
@@ -6585,7 +6585,7 @@
 static void *
 lys_compile_extension_instance_storage(enum ly_stmt stmt, struct lysc_ext_substmt *substmts)
 {
-    for (unsigned int u = 0; substmts[u].stmt; ++u) {
+    for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) {
         if (substmts[u].stmt == stmt) {
             return substmts[u].storage;
         }
@@ -6597,7 +6597,7 @@
 lys_compile_extension_instance(struct lysc_ctx *ctx, const struct lysp_ext_instance *ext, struct lysc_ext_substmt *substmts)
 {
     LY_ERR ret = LY_EVALID, r;
-    unsigned int u;
+    LY_ARRAY_COUNT_TYPE u;
     struct lysp_stmt *stmt;
     void *parsed = NULL, **compiled = NULL;
 
@@ -6623,7 +6623,7 @@
     /* keep order of the processing the same as the order in the defined substmts,
      * the order is important for some of the statements depending on others (e.g. type needs status and units) */
     for (u = 0; substmts[u].stmt; ++u) {
-        int stmt_present = 0;
+        uint8_t stmt_present = 0;
 
         for (stmt = ext->child; stmt; stmt = stmt->next) {
             if (substmts[u].stmt != stmt->kw) {
@@ -6735,7 +6735,6 @@
     struct lyxp_set_scnode *xp_scnode;
     uint32_t i, j;
     LY_ARRAY_COUNT_TYPE u;
-    int idx;
     struct lysc_when *when;
     LY_ERR ret = LY_SUCCESS;
 
@@ -6780,7 +6779,7 @@
                     /* skip roots'n'stuff */
                     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[j].scnode, LYXP_NODE_ELEM, -1);
+                        int 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;
@@ -6824,7 +6823,8 @@
     struct lyxp_set tmp_set;
     uint32_t i;
     LY_ARRAY_COUNT_TYPE u;
-    int opts, input_done = 0;
+    uint32_t opts;
+    uint8_t input_done = 0;
     struct lysc_when **when = NULL;
     struct lysc_must *musts = NULL;
     LY_ERR ret = LY_SUCCESS;
@@ -7157,7 +7157,7 @@
         for (u = orig_count; u < LY_ARRAY_COUNT(llist->dflts); ++u) {
             for (v = 0; v < u; ++v) {
                 if (!llist->dflts[u]->realtype->plugin->compare(llist->dflts[u], llist->dflts[v])) {
-                    int dynamic = 0;
+                    uint8_t dynamic = 0;
                     const char *val = llist->type->plugin->print(llist->dflts[u], LY_PREF_SCHEMA, (void *)dflt_mod, &dynamic);
 
                     lysc_update_path(ctx, llist->parent, llist->name);
@@ -7242,7 +7242,7 @@
 }
 
 LY_ERR
-lys_compile(struct lys_module **mod, int options)
+lys_compile(struct lys_module **mod, uint32_t options)
 {
     struct lysc_ctx ctx = {0};
     struct lysc_module *mod_c;
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 3259bd6..062b993 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -880,7 +880,7 @@
 API void
 lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts)
 {
-    for (unsigned int u = 0; substmts[u].stmt; ++u) {
+    for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) {
         if (!substmts[u].storage) {
             continue;
         }
diff --git a/src/tree_schema_helpers.c b/src/tree_schema_helpers.c
index 4fbf992..260921a 100644
--- a/src/tree_schema_helpers.c
+++ b/src/tree_schema_helpers.c
@@ -36,7 +36,7 @@
 
 LY_ERR
 lysc_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t nodeid_len, const struct lysc_node *context_node,
-        const struct lys_module *context_module, int nodetype, int implement,
+        const struct lys_module *context_module, uint16_t nodetype, uint8_t implement,
         const struct lysc_node **target, uint16_t *result_flag)
 {
     LY_ERR ret = LY_EVALID;
@@ -44,8 +44,8 @@
     size_t name_len, prefix_len;
     const struct lys_module *mod;
     const char *nodeid_type;
-    int getnext_extra_flag = 0;
-    int current_nodetype = 0;
+    uint32_t getnext_extra_flag = 0;
+    uint16_t current_nodetype = 0;
 
     assert(nodeid);
     assert(target);
@@ -193,9 +193,8 @@
 }
 
 LY_ERR
-lysp_check_date(struct lys_parser_ctx *ctx, const char *date, int date_len, const char *stmt)
+lysp_check_date(struct lys_parser_ctx *ctx, const char *date, uint8_t date_len, const char *stmt)
 {
-    int i;
     struct tm tm, tm_;
     char *r;
 
@@ -203,7 +202,7 @@
     LY_CHECK_ERR_RET(date_len != LY_REV_SIZE - 1, LOGARG(ctx ? PARSER_CTX(ctx) : NULL, date_len), LY_EINVAL);
 
     /* check format */
-    for (i = 0; i < date_len; i++) {
+    for (uint8_t i = 0; i < date_len; i++) {
         if (i == 4 || i == 7) {
             if (date[i] != '-') {
                 goto error;
@@ -524,10 +523,10 @@
     return LY_SUCCESS;
 }
 
-static int
-lysp_id_cmp(void *val1, void *val2, int UNUSED(mod), void *UNUSED(cb_data))
+static uint8_t
+lysp_id_cmp(void *val1, void *val2, uint8_t UNUSED(mod), void *UNUSED(cb_data))
 {
-    return !strcmp(val1, val2);
+    return strcmp(val1, val2) == 0 ? 1 : 0;
 }
 
 LY_ERR
@@ -745,8 +744,8 @@
 }
 
 LY_ERR
-lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, int implement,
-        struct lys_parser_ctx *main_ctx, const char *main_name, int required, void **result)
+lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, uint8_t implement,
+        struct lys_parser_ctx *main_ctx, const char *main_name, uint8_t required, void **result)
 {
     struct ly_in *in;
     char *filepath = NULL;
@@ -804,7 +803,7 @@
 }
 
 LY_ERR
-lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, int implement, int require_parsed,
+lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, uint8_t implement, uint8_t require_parsed,
         struct lys_module **mod)
 {
     const char *module_data = NULL;
@@ -930,7 +929,7 @@
 }
 
 LY_ERR
-lysp_check_stringchar(struct lys_parser_ctx *ctx, unsigned int c)
+lysp_check_stringchar(struct lys_parser_ctx *ctx, uint32_t c)
 {
     if (!is_yangutf8char(c)) {
         LOGVAL_PARSER(ctx, LY_VCODE_INCHAR, c);
@@ -940,11 +939,11 @@
 }
 
 LY_ERR
-lysp_check_identifierchar(struct lys_parser_ctx *ctx, unsigned int c, int first, int *prefix)
+lysp_check_identifierchar(struct lys_parser_ctx *ctx, uint32_t c, uint8_t first, uint8_t *prefix)
 {
     if (first || (prefix && (*prefix) == 1)) {
         if (!is_yangidentstartchar(c)) {
-            LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '%c'.", c);
+            LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier first character '%c' (0x%04x).", (char)c, c);
             return LY_EVALID;
         }
         if (prefix) {
@@ -957,7 +956,7 @@
     } else if (c == ':' && prefix && (*prefix) == 0) {
         (*prefix) = 1;
     } else if (!is_yangidentchar(c)) {
-        LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier character '%c'.", c);
+        LOGVAL_PARSER(ctx, LYVE_SYNTAX_YANG, "Invalid identifier character '%c' (0x%04x).", (char)c, c);
         return LY_EVALID;
     }
 
@@ -1403,9 +1402,7 @@
 struct lys_module *
 lysp_find_module(struct ly_ctx *ctx, const struct lysp_module *mod)
 {
-    unsigned int u;
-
-    for (u = 0; u < ctx->list.count; ++u) {
+    for (uint32_t u = 0; u < ctx->list.count; ++u) {
         if (((struct lys_module *)ctx->list.objs[u])->parsed == mod) {
             return ((struct lys_module *)ctx->list.objs[u]);
         }
@@ -1651,7 +1648,7 @@
     return parent;
 }
 
-int
+uint8_t
 lysc_is_output(const struct lysc_node *schema)
 {
     const struct lysc_node *parent;
@@ -1665,7 +1662,7 @@
     return 0;
 }
 
-API int
+API uint8_t
 lysc_is_userordered(const struct lysc_node *schema)
 {
     if (!schema || !(schema->nodetype & (LYS_LEAFLIST | LYS_LIST)) || !(schema->flags & LYS_ORDBY_USER)) {
diff --git a/src/tree_schema_internal.h b/src/tree_schema_internal.h
index 4e16e0c..e0b46b3 100644
--- a/src/tree_schema_internal.h
+++ b/src/tree_schema_internal.h
@@ -184,8 +184,8 @@
     struct ly_set leafrefs;     /**< when/must to check */
     struct ly_set dflts;        /**< set of incomplete default values */
     struct ly_set tpdf_chain;
-    uint16_t path_len;
-    int options;                /**< various @ref scflags. */
+    uint32_t path_len;
+    uint32_t options;           /**< various @ref scflags. */
 #define LYSC_CTX_BUFSIZE 4078
     char path[LYSC_CTX_BUFSIZE];
 };
@@ -197,7 +197,7 @@
  * @param[in] c UTF8 code point of a character to check.
  * @return LY_ERR values.
  */
-LY_ERR lysp_check_stringchar(struct lys_parser_ctx *ctx, unsigned int c);
+LY_ERR lysp_check_stringchar(struct lys_parser_ctx *ctx, uint32_t c);
 
 /**
  * @brief Check that \p c is valid UTF8 code point for YANG identifier.
@@ -213,7 +213,7 @@
  * If the identifier cannot be prefixed, NULL is expected.
  * @return LY_ERR values.
  */
-LY_ERR lysp_check_identifierchar(struct lys_parser_ctx *ctx, unsigned int c, int first, int *prefix);
+LY_ERR lysp_check_identifierchar(struct lys_parser_ctx *ctx, uint32_t c, uint8_t first, uint8_t *prefix);
 
 /**
  * @brief Check the currently present prefixes in the module for collision with the new one.
@@ -235,7 +235,7 @@
  * @param[in] stmt Statement name for error message.
  * @return LY_ERR value.
  */
-LY_ERR lysp_check_date(struct lys_parser_ctx *ctx, const char *date, int date_len, const char *stmt);
+LY_ERR lysp_check_date(struct lys_parser_ctx *ctx, const char *date, uint8_t date_len, const char *stmt);
 
 /**
  * @brief Check names of typedefs in the parsed module to detect collisions.
@@ -304,7 +304,7 @@
  * @param[out] mod Parsed module structure.
  * @return LY_ERR value.
  */
-LY_ERR lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, int implement, int require_parsed, struct lys_module **mod);
+LY_ERR lysp_load_module(struct ly_ctx *ctx, const char *name, const char *revision, uint8_t implement, uint8_t require_parsed, struct lys_module **mod);
 
 /**
  * @brief Parse included submodule into the simply parsed YANG module.
@@ -325,7 +325,7 @@
  * @param[in] options Various options to modify compiler behavior, see [compile flags](@ref scflags).
  * @return LY_ERR value - LY_SUCCESS or LY_EVALID.
  */
-LY_ERR lys_compile(struct lys_module **mod, int options);
+LY_ERR lys_compile(struct lys_module **mod, uint32_t options);
 
 /**
  * @brief Get address of a node's actions list if any.
@@ -443,7 +443,7 @@
  * @return LY_ERR values - LY_ENOTFOUND, LY_EVALID, LY_EDENIED or LY_SUCCESS.
  */
 LY_ERR lysc_resolve_schema_nodeid(struct lysc_ctx *ctx, const char *nodeid, size_t nodeid_len, const struct lysc_node *context_node,
-        const struct lys_module *context_module, int nodetype, int implement,
+        const struct lys_module *context_module, uint16_t nodetype, uint8_t implement,
         const struct lysc_node **target, uint16_t *result_flag);
 
 /**
@@ -496,7 +496,7 @@
  * @param[out] module Parsed module.
  * @return LY_ERR value.
  */
-LY_ERR lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, int implement,
+LY_ERR lys_parse_mem_module(struct ly_ctx *ctx, struct ly_in *in, LYS_INFORMAT format, uint8_t implement,
         lys_custom_check custom_check, void *check_data, struct lys_module **module);
 
 /**
@@ -545,8 +545,8 @@
  * If it is a module, it is already in the context!
  * @return LY_ERR value, in case of LY_SUCCESS, the \arg result is always provided.
  */
-LY_ERR lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, int implement,
-        struct lys_parser_ctx *main_ctx, const char *main_name, int required, void **result);
+LY_ERR lys_module_localfile(struct ly_ctx *ctx, const char *name, const char *revision, uint8_t implement,
+        struct lys_parser_ctx *main_ctx, const char *main_name, uint8_t required, void **result);
 
 /**
  * @brief Compile information from the identity statement
@@ -595,7 +595,7 @@
  * @param[in] list The 2bits array with the compiled if-feature expression.
  * @param[in] pos Position (0-based) to specify from which position get the operator.
  */
-uint8_t lysc_iff_getop(uint8_t *list, int pos);
+uint8_t lysc_iff_getop(uint8_t *list, size_t pos);
 
 /**
  * @brief Checks pattern syntax.
@@ -781,12 +781,12 @@
 const struct lysc_node *lysc_data_parent(const struct lysc_node *schema);
 
 /**
- * @brief Learn whether a node is in an operation output.
+ * @brief Learn whether a node is inside an operation output.
  *
  * @param[in] schema Schema node to examine.
- * @return non-zero is the node is in output,
  * @return 0 if it is not.
+ * @return 1 if the node is under an operation output
  */
-int lysc_is_output(const struct lysc_node *schema);
+uint8_t lysc_is_output(const struct lysc_node *schema);
 
 #endif /* LY_TREE_SCHEMA_INTERNAL_H_ */
diff --git a/src/validation.c b/src/validation.c
index 3bf851d..1a9dcee 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -126,7 +126,7 @@
                 /* evaluate all when expressions that affect this node's existence */
                 struct lyd_node *node = (struct lyd_node *)node_when->objs[i];
                 const struct lysc_node *schema = node->schema;
-                int unres_when = 0;
+                uint8_t unres_when = 0;
 
                 do {
                     LY_ARRAY_COUNT_TYPE u;
@@ -213,7 +213,7 @@
 lyd_validate_duplicates(const struct lyd_node *first, const struct lyd_node *node)
 {
     struct lyd_node **match_p;
-    int fail = 0;
+    uint8_t fail = 0;
 
     if ((node->schema->nodetype & (LYS_LIST | LYS_LEAFLIST)) && (node->schema->flags & LYS_CONFIG_R)) {
         /* duplicate instances allowed */
@@ -263,7 +263,7 @@
 {
     const struct lysc_node *scase, *iter, *old_case = NULL, *new_case = NULL;
     struct lyd_node *match, *to_del;
-    int found;
+    uint8_t found;
 
     LY_LIST_FOR((struct lysc_node *)choic->cases, scase) {
         found = 0;
@@ -565,8 +565,8 @@
  *
  * @param[in] cb_data 0 to compare all uniques, n to compare only n-th unique.
  */
-static int
-lyd_val_uniq_list_equal(void *val1_p, void *val2_p, int UNUSED(mod), void *cb_data)
+static uint8_t
+lyd_val_uniq_list_equal(void *val1_p, void *val2_p, uint8_t UNUSED(mod), void *cb_data)
 {
     struct ly_ctx *ctx;
     struct lysc_node_list *slist;
@@ -677,7 +677,7 @@
     LY_ARRAY_COUNT_TYPE u, v, x = 0;
     LY_ERR ret = LY_SUCCESS;
     uint32_t hash, i, size = 0;
-    int dynamic;
+    uint8_t dynamic;
     const char *str;
     struct hash_table **uniqtables = NULL;
     struct lyd_value *val;
@@ -792,12 +792,12 @@
  */
 static LY_ERR
 lyd_validate_siblings_schema_r(const struct lyd_node *first, const struct lysc_node *sparent,
-        const struct lysc_module *mod, int val_opts, LYD_VALIDATE_OP op)
+        const struct lysc_module *mod, uint32_t val_opts, LYD_VALIDATE_OP op)
 {
     const struct lysc_node *snode = NULL;
     struct lysc_node_list *slist;
     struct lysc_node_leaflist *sllist;
-    int getnext_opts;
+    uint32_t getnext_opts;
 
     getnext_opts = LYS_GETNEXT_WITHCHOICE | LYS_GETNEXT_WITHCASE | (op == LYD_VALIDATE_OP_REPLY ? LYS_GETNEXT_OUTPUT : 0);
 
@@ -943,7 +943,7 @@
 }
 
 LY_ERR
-lyd_validate_final_r(struct lyd_node *first, const struct lysc_node *sparent, const struct lys_module *mod, int val_opts,
+lyd_validate_final_r(struct lyd_node *first, const struct lysc_node *sparent, const struct lys_module *mod, uint32_t val_opts,
         LYD_VALIDATE_OP op)
 {
     struct lyd_node *next = NULL, *node;
@@ -1026,7 +1026,7 @@
  */
 static LY_ERR
 lyd_validate_subtree(struct lyd_node *root, struct ly_set *type_check, struct ly_set *type_meta_check,
-        struct ly_set *when_check, int val_opts, struct lyd_node **diff)
+        struct ly_set *when_check, uint32_t val_opts, struct lyd_node **diff)
 {
     const struct lyd_meta *meta;
     struct lyd_node *node;
@@ -1076,7 +1076,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, int val_opts,
+lyd_validate(struct lyd_node **tree, const struct lys_module *module, const struct ly_ctx *ctx, uint32_t val_opts,
         struct lyd_node **diff)
 {
     LY_ERR ret = LY_SUCCESS;
@@ -1139,13 +1139,13 @@
 }
 
 API LY_ERR
-lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, int val_opts, struct lyd_node **diff)
+lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, struct lyd_node **diff)
 {
     return lyd_validate(tree, NULL, ctx, val_opts, diff);
 }
 
 API LY_ERR
-lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, int val_opts, struct lyd_node **diff)
+lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, struct lyd_node **diff)
 {
     return lyd_validate(tree, module, NULL, val_opts, diff);
 }
diff --git a/src/validation.h b/src/validation.h
index 4cdf277..1a1a00a 100644
--- a/src/validation.h
+++ b/src/validation.h
@@ -74,6 +74,6 @@
  * @return LY_ERR value.
  */
 LY_ERR lyd_validate_final_r(struct lyd_node *first, const struct lysc_node *sparent, const struct lys_module *mod,
-        int val_opts, LYD_VALIDATE_OP op);
+        uint32_t val_opts, LYD_VALIDATE_OP op);
 
 #endif /* LY_VALIDATION_H_ */
diff --git a/src/xml.c b/src/xml.c
index 933fa52..ad4f54e 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -38,16 +38,16 @@
 /* Ignore whitespaces in the input string p */
 #define ign_xmlws(c) while (is_xmlws(*(c)->in->current)) {if (*(c)->in->current == '\n') {++c->line;} ly_in_skip(c->in, 1);}
 
-static LY_ERR lyxml_next_attr_content(struct lyxml_ctx *xmlctx, const char **value, size_t *value_len, int *ws_only,
-        int *dynamic);
+static LY_ERR lyxml_next_attr_content(struct lyxml_ctx *xmlctx, const char **value, size_t *value_len, uint8_t *ws_only,
+        uint8_t *dynamic);
 
 /**
  * @brief Ignore any characters until the delim of the size delim_len is read
  *
  * Detects number of read new lines.
- * Returns 0 if delim was found, non-zero if was not.
+ * Returns 0 if delim was found, 1 if was not.
  */
-static int
+static uint8_t
 ign_todelim(register const char *input, const char *delim, size_t delim_len, size_t *newlines, size_t *parsed)
 {
     size_t i;
@@ -76,7 +76,7 @@
     }
 
     /* delim not found */
-    return -1;
+    return 1;
 }
 
 /**
@@ -176,9 +176,7 @@
 void
 lyxml_ns_rm(struct lyxml_ctx *xmlctx)
 {
-    unsigned int u;
-
-    for (u = xmlctx->ns.count - 1; u + 1 > 0; --u) {
+    for (uint32_t u = xmlctx->ns.count - 1; u + 1 > 0; --u) {
         if (((struct lyxml_ns *)xmlctx->ns.objs[u])->depth != xmlctx->elements.count + 1) {
             /* we are done, the namespaces from a single element are supposed to be together */
             break;
@@ -199,10 +197,9 @@
 const struct lyxml_ns *
 lyxml_ns_get(const struct ly_set *ns_set, const char *prefix, size_t prefix_len)
 {
-    unsigned int u;
     struct lyxml_ns *ns;
 
-    for (u = ns_set->count - 1; u + 1 > 0; --u) {
+    for (uint32_t u = ns_set->count - 1; u + 1 > 0; --u) {
         ns = (struct lyxml_ns *)ns_set->objs[u];
         if (prefix && prefix_len) {
             if (ns->prefix && !ly_strncmp(ns->prefix, prefix, prefix_len)) {
@@ -230,7 +227,7 @@
     const struct ly_ctx *ctx = xmlctx->ctx; /* shortcut */
     const char *endtag, *sectname;
     size_t endtag_len, newlines, parsed;
-    int rc;
+    uint8_t rc;
 
     while (1) {
         ign_xmlws(xmlctx);
@@ -336,7 +333,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t *length, int *ws_only, int *dynamic)
+lyxml_parse_value(struct lyxml_ctx *xmlctx, char endchar, char **value, size_t *length, uint8_t *ws_only, uint8_t *dynamic)
 {
 #define BUFSIZE 24
 #define BUFSIZE_STEP 128
@@ -350,7 +347,7 @@
     void *p;
     uint32_t n;
     size_t u;
-    int ws = 1;
+    uint8_t ws = 1;
 
     assert(xmlctx);
 
@@ -519,7 +516,7 @@
  */
 static LY_ERR
 lyxml_close_element(struct lyxml_ctx *xmlctx, const char *prefix, size_t prefix_len, const char *name, size_t name_len,
-        int empty)
+        uint8_t empty)
 {
     struct lyxml_elem *e;
 
@@ -585,7 +582,7 @@
     const char *prev_input;
     char *value;
     size_t parsed, value_len;
-    int ws_only, dynamic, is_ns;
+    uint8_t ws_only, dynamic, is_ns;
     uint32_t c;
 
     /* store element opening tag information */
@@ -652,7 +649,7 @@
  * @return LY_ERR value.
  */
 static LY_ERR
-lyxml_next_attr_content(struct lyxml_ctx *xmlctx, const char **value, size_t *value_len, int *ws_only, int *dynamic)
+lyxml_next_attr_content(struct lyxml_ctx *xmlctx, const char **value, size_t *value_len, uint8_t *ws_only, uint8_t *dynamic)
 {
     char quot;
 
@@ -713,7 +710,7 @@
     char *value;
     uint32_t c;
     size_t parsed, value_len;
-    int ws_only, dynamic;
+    uint8_t ws_only, dynamic;
 
     /* skip WS */
     ign_xmlws(xmlctx);
@@ -759,11 +756,12 @@
  * @param[out] prefix_len Length of @p prefix.
  * @param[out] name Parse element name.
  * @param[out] name_len Length of @p name.
+ * @param[out] closing Flag if the element is closing (includes '/').
  * @return LY_ERR value.
  */
 static LY_ERR
 lyxml_next_element(struct lyxml_ctx *xmlctx, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len,
-        int *closing)
+        uint8_t *closing)
 {
     /* skip WS until EOF or after opening tag '<' */
     LY_CHECK_RET(lyxml_skip_until_end_or_after_otag(xmlctx));
@@ -795,7 +793,7 @@
 {
     LY_ERR ret = LY_SUCCESS;
     struct lyxml_ctx *xmlctx;
-    int closing;
+    uint8_t closing;
 
     /* new context */
     xmlctx = calloc(1, sizeof *xmlctx);
@@ -837,7 +835,7 @@
 lyxml_ctx_next(struct lyxml_ctx *xmlctx)
 {
     LY_ERR ret = LY_SUCCESS;
-    int closing;
+    uint8_t closing;
     struct lyxml_elem *e;
 
     /* if the value was not used, free it */
@@ -967,7 +965,7 @@
     LY_ERR ret = LY_SUCCESS;
     const char *prefix, *name, *prev_input;
     size_t prefix_len, name_len;
-    int closing;
+    uint8_t closing;
 
     prev_input = xmlctx->in->current;
 
@@ -1040,16 +1038,15 @@
 }
 
 LY_ERR
-lyxml_dump_text(struct ly_out *out, const char *text, int attribute)
+lyxml_dump_text(struct ly_out *out, const char *text, uint8_t attribute)
 {
     LY_ERR ret;
-    unsigned int u;
 
     if (!text) {
         return 0;
     }
 
-    for (u = 0; text[u]; u++) {
+    for (uint64_t u = 0; text[u]; u++) {
         switch (text[u]) {
         case '&':
             ret = ly_print_(out, "&amp;");
@@ -1138,7 +1135,6 @@
 {
     const char *ptr1, *ptr2, *ns1, *ns2;
     LY_ARRAY_COUNT_TYPE u1, u2;
-    int len;
 
     if (!value1 && !value2) {
         return LY_SUCCESS;
@@ -1152,6 +1148,7 @@
     while (ptr1[0] && ptr2[0]) {
         if (ptr1[0] != ptr2[0]) {
             /* it can be a start of prefix that maps to the same module */
+            size_t len;
             ns1 = ns2 = NULL;
             u1 = u2 = 0;
             if (prefs1) {
diff --git a/src/xml.h b/src/xml.h
index 8f4b47e..2be61b1 100644
--- a/src/xml.h
+++ b/src/xml.h
@@ -92,11 +92,11 @@
     };
     union {
         const char *name;   /* LYXML_ELEMENT, LYXML_ATTRIBUTE - elem/attr name */
-        int ws_only;        /* LYXML_ELEM_CONTENT, LYXML_ATTR_CONTENT - whether elem/attr value is empty/white-space only */
+        uint8_t ws_only;    /* LYXML_ELEM_CONTENT, LYXML_ATTR_CONTENT - whether elem/attr value is empty/white-space only */
     };
     union {
         size_t name_len;    /* LYXML_ELEMENT, LYXML_ATTRIBUTE - elem/attr name length */
-        int dynamic;        /* LYXML_ELEM_CONTENT, LYXML_ATTR_CONTENT - whether elem/attr value is dynamically allocated */
+        uint8_t dynamic;    /* LYXML_ELEM_CONTENT, LYXML_ATTR_CONTENT - whether elem/attr value is dynamically allocated */
     };
 
     struct ly_set elements; /* list of not-yet-closed elements */
@@ -153,7 +153,7 @@
  * @param[in] attribute Flag for attribute's value where a double quotes must be replaced.
  * @return LY_ERR values.
  */
-LY_ERR lyxml_dump_text(struct ly_out *out, const char *text, int attribute);
+LY_ERR lyxml_dump_text(struct ly_out *out, const char *text, uint8_t attribute);
 
 /**
  * @brief Remove the allocated working memory of the context.
diff --git a/src/xpath.c b/src/xpath.c
index 4072aab..9b9e835 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -44,7 +44,7 @@
 #include "xml.h"
 
 static LY_ERR reparse_or_expr(const struct ly_ctx *ctx, struct lyxp_expr *exp, uint16_t *tok_idx);
-static LY_ERR eval_expr_select(struct lyxp_expr *exp, uint16_t *tok_idx, enum lyxp_expr_type etype, struct lyxp_set *set, int options);
+static LY_ERR eval_expr_select(struct lyxp_expr *exp, uint16_t *tok_idx, enum lyxp_expr_type etype, struct lyxp_set *set, uint32_t options);
 
 /**
  * @brief Print the type of an XPath \p set.
@@ -318,7 +318,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-cast_string_recursive(const struct lyd_node *node, int fake_cont, enum lyxp_node_type root_type, uint16_t indent, char **str,
+cast_string_recursive(const struct lyd_node *node, uint8_t fake_cont, enum lyxp_node_type root_type, uint16_t indent, char **str,
         uint16_t *used, uint16_t *size)
 {
     char *buf, *line, *ptr = NULL;
@@ -464,7 +464,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-cast_string_elem(struct lyd_node *node, int fake_cont, enum lyxp_node_type root_type, char **str)
+cast_string_elem(struct lyd_node *node, uint8_t fake_cont, enum lyxp_node_type root_type, char **str)
 {
     uint16_t used, size;
     LY_ERR rc;
@@ -549,8 +549,8 @@
  * @param[in] cb_data Callback data.
  * @return 0 if not equal, non-zero if equal.
  */
-static int
-set_values_equal_cb(void *val1_p, void *val2_p, int UNUSED(mod), void *UNUSED(cb_data))
+static uint8_t
+set_values_equal_cb(void *val1_p, void *val2_p, uint8_t UNUSED(mod), void *UNUSED(cb_data))
 {
     struct lyxp_set_hash_node *val1, *val2;
 
@@ -574,7 +574,7 @@
 static void
 set_insert_node_hash(struct lyxp_set *set, struct lyd_node *node, enum lyxp_node_type type)
 {
-    int r;
+    LY_ERR r;
     uint32_t i, hash;
     struct lyxp_set_hash_node hnode;
 
@@ -625,7 +625,7 @@
 static void
 set_remove_node_hash(struct lyxp_set *set, struct lyd_node *node, enum lyxp_node_type type)
 {
-    int r;
+    LY_ERR r;
     struct lyxp_set_hash_node hnode;
     uint32_t hash;
 
@@ -763,7 +763,6 @@
 {
     struct lyxp_set *ret;
     uint16_t i;
-    int idx;
 
     if (!set) {
         return NULL;
@@ -778,7 +777,7 @@
 
         for (i = 0; i < set->used; ++i) {
             if ((set->val.scnodes[i].in_ctx == 1) || (set->val.scnodes[i].in_ctx == -2)) {
-                idx = lyxp_set_scnode_insert_node(ret, set->val.scnodes[i].scnode, set->val.scnodes[i].type);
+                int idx = lyxp_set_scnode_insert_node(ret, set->val.scnodes[i].scnode, set->val.scnodes[i].type);
                 /* coverity seems to think scnodes can be NULL */
                 if ((idx == -1) || !ret->val.scnodes) {
                     lyxp_set_free(ret);
@@ -849,7 +848,7 @@
  * @param[in] boolean Boolean to fill into \p set.
  */
 static void
-set_fill_boolean(struct lyxp_set *set, int boolean)
+set_fill_boolean(struct lyxp_set *set, uint8_t boolean)
 {
     lyxp_set_free_content(set);
 
@@ -1509,7 +1508,7 @@
     struct lyd_value val;
     struct ly_err_item *err = NULL;
     char *str, *ptr;
-    int dynamic;
+    uint8_t dynamic;
     LY_ERR rc;
 
     /* is there anything to canonize even? */
@@ -1583,7 +1582,8 @@
 set_sort(struct lyxp_set *set)
 {
     uint32_t i, j;
-    int ret = 0, cmp, inverted, change;
+    int ret = 0, cmp;
+    uint8_t inverted, change;
     const struct lyd_node *root;
     struct lyxp_set_node item;
     struct lyxp_set_hash_node hnode;
@@ -2079,7 +2079,8 @@
 static LY_ERR
 reparse_function_call(const struct ly_ctx *ctx, struct lyxp_expr *exp, uint16_t *tok_idx)
 {
-    int min_arg_count = -1, max_arg_count, arg_count;
+    int8_t min_arg_count = -1;
+    uint32_t arg_count, max_arg_count = 0;
     uint16_t func_tok_idx;
     LY_ERR rc;
 
@@ -2132,7 +2133,7 @@
     case 6:
         if (!strncmp(&exp->expr[exp->tok_pos[*tok_idx]], "concat", 6)) {
             min_arg_count = 2;
-            max_arg_count = INT_MAX;
+            max_arg_count = UINT32_MAX;
         } else if (!strncmp(&exp->expr[exp->tok_pos[*tok_idx]], "number", 6)) {
             min_arg_count = 0;
             max_arg_count = 1;
@@ -2262,7 +2263,7 @@
     LY_CHECK_RET(rc);
     ++(*tok_idx);
 
-    if ((arg_count < min_arg_count) || (arg_count > max_arg_count)) {
+    if ((arg_count < (uint8_t)min_arg_count) || (arg_count > max_arg_count)) {
         LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INARGCOUNT, arg_count, exp->tok_len[func_tok_idx],
                &exp->expr[exp->tok_pos[func_tok_idx]]);
         return LY_EVALID;
@@ -2561,7 +2562,7 @@
 static long int
 parse_ncname(const char *ncname)
 {
-    unsigned int uc;
+    uint32_t uc;
     size_t size;
     long int len = 0;
 
@@ -2642,13 +2643,12 @@
 }
 
 struct lyxp_expr *
-lyxp_expr_parse(const struct ly_ctx *ctx, const char *expr, size_t expr_len, int reparse)
+lyxp_expr_parse(const struct ly_ctx *ctx, const char *expr, size_t expr_len, uint8_t reparse)
 {
     struct lyxp_expr *ret;
     size_t parsed = 0, tok_len;
-    long int ncname_len;
     enum lyxp_token tok_type;
-    int prev_function_check = 0;
+    uint8_t prev_function_check = 0;
     uint16_t tok_idx = 0;
 
     if (!expr[0]) {
@@ -2872,7 +2872,7 @@
         } else {
 
             /* NameTest (NCName ':' '*' | QName) or NodeType/FunctionName */
-            ncname_len = parse_ncname(&expr[parsed]);
+            long int ncname_len = parse_ncname(&expr[parsed]);
             LY_CHECK_ERR_GOTO(ncname_len < 0, LOGVAL(ctx, LY_VLOG_NONE, NULL, LY_VCODE_XP_INEXPR, parsed - ncname_len + 1, expr), error);
             tok_len = ncname_len;
 
@@ -3016,11 +3016,11 @@
  * @param[in] type Type to test.
  * @return 1 if numeric, 0 otherwise.
  */
-static int
+static uint8_t
 warn_is_numeric_type(struct lysc_type *type)
 {
     struct lysc_type_union *uni;
-    int ret;
+    uint8_t ret;
     LY_ARRAY_COUNT_TYPE u;
 
     switch (type->basetype) {
@@ -3058,11 +3058,11 @@
  * @param[in] type Type to test.
  * @return 1 if string, 0 otherwise.
  */
-static int
+static uint8_t
 warn_is_string_type(struct lysc_type *type)
 {
     struct lysc_type_union *uni;
-    int ret;
+    uint8_t ret;
     LY_ARRAY_COUNT_TYPE u;
 
     switch (type->basetype) {
@@ -3097,11 +3097,11 @@
  * @param[in] base Expected type.
  * @return 1 if it is, 0 otherwise.
  */
-static int
+static uint8_t
 warn_is_specific_type(struct lysc_type *type, LY_DATA_TYPE base)
 {
     struct lysc_type_union *uni;
-    int ret;
+    uint8_t ret;
     LY_ARRAY_COUNT_TYPE u;
 
     if (type->basetype == base) {
@@ -3135,7 +3135,7 @@
 warn_is_equal_type_next_type(struct lysc_type *type, struct lysc_type *prev_type)
 {
     struct lysc_type_union *uni;
-    int found = 0;
+    uint8_t found = 0;
     LY_ARRAY_COUNT_TYPE u;
 
     switch (type->basetype) {
@@ -3212,10 +3212,10 @@
  * @param[in] tok_pos Token position.
  */
 static void
-warn_operands(struct ly_ctx *ctx, struct lyxp_set *set1, struct lyxp_set *set2, int numbers_only, const char *expr, uint16_t tok_pos)
+warn_operands(struct ly_ctx *ctx, struct lyxp_set *set1, struct lyxp_set *set2, uint8_t numbers_only, const char *expr, uint16_t tok_pos)
 {
     struct lysc_node_leaf *node1, *node2;
-    int leaves = 1, warning = 0;
+    uint8_t leaves = 1, warning = 0;
 
     node1 = (struct lysc_node_leaf *)warn_get_scnode_in_ctx(set1);
     node2 = (struct lysc_node_leaf *)warn_get_scnode_in_ctx(set2);
@@ -3340,7 +3340,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_bit_is_set(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_bit_is_set(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lyd_node_term *leaf;
     struct lysc_node_leaf *sleaf;
@@ -3404,7 +3404,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_boolean(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_boolean(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
 
@@ -3431,7 +3431,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_ceiling(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_ceiling(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -3470,7 +3470,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_concat(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_concat(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     uint16_t i;
     char *str = NULL;
@@ -3526,7 +3526,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_contains(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_contains(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -3576,7 +3576,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_count(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_count(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node *scnode = NULL;
     LY_ERR rc = LY_SUCCESS;
@@ -3609,7 +3609,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_current(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_current(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     if (arg_count || args) {
         LOGVAL(set->ctx, LY_VLOG_LYD, set->ctx_node, LY_VCODE_XP_INARGCOUNT, arg_count, "current()");
@@ -3641,7 +3641,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_deref(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_deref(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lyd_node_term *leaf;
     struct lysc_node_leaf *sleaf = NULL;
@@ -3718,7 +3718,7 @@
 }
 
 static LY_ERR
-xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, int options, int self_match, const char *func)
+xpath_derived_(struct lyxp_set **args, struct lyxp_set *set, uint32_t options, uint8_t self_match, const char *func)
 {
     uint16_t i;
     LY_ARRAY_COUNT_TYPE u;
@@ -3728,7 +3728,7 @@
     struct lyd_value data = {0}, *val;
     struct ly_err_item *err = NULL;
     LY_ERR rc = LY_SUCCESS;
-    int found;
+    uint8_t found;
 
     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]))) {
@@ -3837,7 +3837,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_derived_from(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_derived_from(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     return xpath_derived_(args, set, options, 0, __func__);
 }
@@ -3854,7 +3854,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_derived_from_or_self(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_derived_from_or_self(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     return xpath_derived_(args, set, options, 1, __func__);
 }
@@ -3870,7 +3870,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_enum_value(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_enum_value(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lyd_node_term *leaf;
     struct lysc_node_leaf *sleaf;
@@ -3916,7 +3916,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_false(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_false(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -3938,7 +3938,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_floor(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int UNUSED(options))
+xpath_floor(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t UNUSED(options))
 {
     LY_ERR rc;
 
@@ -3962,13 +3962,12 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_lang(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_lang(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     const struct lyd_node *node;
     struct lysc_node_leaf *sleaf;
     struct lyd_meta *meta = NULL;
     const char *val;
-    int i;
     LY_ERR rc = LY_SUCCESS;
 
     if (options & LYXP_SCNODE_ALL) {
@@ -4026,6 +4025,8 @@
     if (!meta) {
         set_fill_boolean(set, 0);
     } else {
+        uint64_t i;
+
         val = meta->value.canonical;
         for (i = 0; args[0]->val.str[i]; ++i) {
             if (tolower(args[0]->val.str[i]) != tolower(val[i])) {
@@ -4056,7 +4057,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_last(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_last(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -4086,7 +4087,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_local_name(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_local_name(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     struct lyxp_set_node *item;
     /* suppress unused variable warning */
@@ -4155,13 +4156,12 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_name(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_name(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     struct lyxp_set_node *item;
     struct lys_module *mod = NULL;
     char *str;
     const char *name = NULL;
-    int rc = -1;
 
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -4215,6 +4215,8 @@
     }
 
     if (mod && name) {
+        int rc = -1;
+
         switch (set->format) {
         case LY_PREF_SCHEMA:
             rc = asprintf(&str, "%s:%s", lys_prefix_find_module(set->local_mod, mod), name);
@@ -4246,7 +4248,7 @@
  * @return LY_ERR (LY_EINVAL for wrong arguments on schema)
  */
 static LY_ERR
-xpath_namespace_uri(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_namespace_uri(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     struct lyxp_set_node *item;
     struct lys_module *mod;
@@ -4323,7 +4325,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_node(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_node(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -4348,11 +4350,11 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_normalize_space(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_normalize_space(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     uint16_t i, new_used;
     char *new;
-    int have_spaces = 0, space_before = 0;
+    uint8_t have_spaces = 0, space_before = 0;
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
 
@@ -4438,7 +4440,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_not(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_not(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -4466,7 +4468,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_number(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_number(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
 
@@ -4498,7 +4500,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_position(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_position(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -4532,7 +4534,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_re_match(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_re_match(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_pattern **patterns = NULL, **pattern;
     struct lysc_node_leaf *sleaf;
@@ -4607,7 +4609,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_round(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_round(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -4652,7 +4654,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_starts_with(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_starts_with(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -4702,7 +4704,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_string(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_string(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
 
@@ -4734,7 +4736,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_string_length(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_string_length(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -4785,9 +4787,9 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_substring(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, int options)
+xpath_substring(struct lyxp_set **args, uint16_t arg_count, struct lyxp_set *set, uint32_t options)
 {
-    int start, len;
+    int32_t start, len;
     uint16_t str_start, str_len, pos;
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
@@ -4831,24 +4833,24 @@
     if (isfinite(args[1]->val.num)) {
         start = args[1]->val.num - 1;
     } else if (isinf(args[1]->val.num) && signbit(args[1]->val.num)) {
-        start = INT_MIN;
+        start = INT32_MIN;
     } else {
-        start = INT_MAX;
+        start = INT32_MAX;
     }
 
     /* len */
     if (arg_count == 3) {
         rc = xpath_round(&args[2], 1, args[2], options);
         LY_CHECK_RET(rc);
-        if (isfinite(args[2]->val.num)) {
-            len = args[2]->val.num;
-        } else if (isnan(args[2]->val.num) || signbit(args[2]->val.num)) {
+        if (isnan(args[2]->val.num) || signbit(args[2]->val.num)) {
             len = 0;
+        } else if (isfinite(args[2]->val.num)) {
+            len = args[2]->val.num;
         } else {
-            len = INT_MAX;
+            len = INT32_MAX;
         }
     } else {
-        len = INT_MAX;
+        len = INT32_MAX;
     }
 
     /* find matching character positions */
@@ -4880,7 +4882,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_substring_after(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_substring_after(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     char *ptr;
     struct lysc_node_leaf *sleaf;
@@ -4933,7 +4935,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_substring_before(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_substring_before(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     char *ptr;
     struct lysc_node_leaf *sleaf;
@@ -4985,7 +4987,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_sum(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_sum(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     long double num;
     char *str;
@@ -5056,7 +5058,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_text(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_text(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     uint32_t i;
 
@@ -5106,11 +5108,11 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_translate(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_translate(struct lyxp_set **args, uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     uint16_t i, j, new_used;
     char *new;
-    int found, have_removed;
+    uint8_t have_removed;
     struct lysc_node_leaf *sleaf;
     LY_ERR rc = LY_SUCCESS;
 
@@ -5155,7 +5157,7 @@
 
     have_removed = 0;
     for (i = 0; args[0]->val.str[i]; ++i) {
-        found = 0;
+        uint8_t found = 0;
 
         for (j = 0; args[1]->val.str[j]; ++j) {
             if (args[0]->val.str[i] == args[1]->val.str[j]) {
@@ -5204,7 +5206,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-xpath_true(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, int options)
+xpath_true(struct lyxp_set **UNUSED(args), uint16_t UNUSED(arg_count), struct lyxp_set *set, uint32_t options)
 {
     if (options & LYXP_SCNODE_ALL) {
         set_scnode_clear_ctx(set);
@@ -5237,7 +5239,7 @@
 {
     const struct lys_module *mod = NULL;
     const char *ptr;
-    int pref_len;
+    size_t pref_len;
 
     assert((set->type == LYXP_SET_NODE_SET) || (set->type == LYXP_SET_SCNODE_SET));
 
@@ -5281,7 +5283,7 @@
  * @param[in] options Xpath options.
  */
 static void
-moveto_root(struct lyxp_set *set, int options)
+moveto_root(struct lyxp_set *set, uint32_t options)
 {
     if (!set) {
         return;
@@ -5411,7 +5413,6 @@
 moveto_node(struct lyxp_set *set, const struct lys_module *mod, const char *ncname)
 {
     uint32_t i;
-    int replaced;
     const struct lyd_node *siblings, *sub;
     LY_ERR rc;
 
@@ -5425,7 +5426,7 @@
     }
 
     for (i = 0; i < set->used; ) {
-        replaced = 0;
+        uint8_t replaced = 0;
 
         if ((set->val.nodes[i].type == LYXP_NODE_ROOT_CONFIG) || (set->val.nodes[i].type == LYXP_NODE_ROOT)) {
             assert(!set->val.nodes[i].node);
@@ -5558,9 +5559,12 @@
  * @return LY_ERR
  */
 static LY_ERR
-moveto_scnode(struct lyxp_set *set, const struct lys_module *mod, const char *ncname, int options)
+moveto_scnode(struct lyxp_set *set, const struct lys_module *mod, const char *ncname, uint32_t options)
 {
-    int i, orig_used, idx, temp_ctx = 0, getnext_opts;
+    int idx;
+    uint8_t temp_ctx = 0;
+    uint32_t getnext_opts;
+    uint32_t orig_used, i;
     uint32_t mod_idx;
     const struct lysc_node *iter, *start_parent;
 
@@ -5604,8 +5608,9 @@
                 while (mod->implemented && (iter = lys_getnext(iter, NULL, mod->compiled, getnext_opts))) {
                     if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, mod)) {
                         idx = lyxp_set_scnode_insert_node(set, iter, LYXP_NODE_ELEM);
+                        LY_CHECK_RET(idx < 0, LY_EMEM);
                         /* we need to prevent these nodes from being considered in this moveto */
-                        if ((idx < orig_used) && (idx > i)) {
+                        if (((uint32_t)idx < orig_used) && ((uint32_t)idx > i)) {
                             set->val.scnodes[idx].in_ctx = 2;
                             temp_ctx = 1;
                         }
@@ -5625,7 +5630,8 @@
             while ((iter = lys_getnext(iter, start_parent, NULL, getnext_opts))) {
                 if (!moveto_scnode_check(iter, set->root_type, set->context_op, ncname, (mod ? mod : set->local_mod))) {
                     idx = lyxp_set_scnode_insert_node(set, iter, LYXP_NODE_ELEM);
-                    if ((idx < orig_used) && (idx > i)) {
+                    LY_CHECK_RET(idx < 0, LY_EMEM);
+                    if (((uint32_t)idx < orig_used) && ((uint32_t)idx > i)) {
                         set->val.scnodes[idx].in_ctx = 2;
                         temp_ctx = 1;
                     }
@@ -5742,9 +5748,10 @@
  * @return LY_ERR
  */
 static LY_ERR
-moveto_scnode_alldesc(struct lyxp_set *set, const struct lys_module *mod, const char *ncname, int options)
+moveto_scnode_alldesc(struct lyxp_set *set, const struct lys_module *mod, const char *ncname, uint32_t options)
 {
-    int i, orig_used, idx;
+    uint32_t i, orig_used;
+    int idx;
     const struct lysc_node *next, *elem, *start;
     LY_ERR rc;
 
@@ -5782,7 +5789,7 @@
             if (!rc) {
                 if ((idx = lyxp_set_scnode_dup_node_check(set, elem, LYXP_NODE_ELEM, i)) > -1) {
                     set->val.scnodes[idx].in_ctx = 1;
-                    if (idx > i) {
+                    if ((uint32_t)idx > i) {
                         /* we will process it later in the set */
                         goto skip_children;
                     }
@@ -5835,8 +5842,6 @@
 static LY_ERR
 moveto_attr(struct lyxp_set *set, const struct lys_module *mod, const char *ncname)
 {
-    uint32_t i;
-    int replaced;
     struct lyd_meta *sub;
 
     if (!set) {
@@ -5848,8 +5853,8 @@
         return LY_EVALID;
     }
 
-    for (i = 0; i < set->used; ) {
-        replaced = 0;
+    for (uint32_t i = 0; i < set->used; ) {
+        uint8_t replaced = 0;
 
         /* only attributes of an elem (not dummy) can be in the result, skip all the rest;
          * our attributes are always qualified */
@@ -5940,8 +5945,6 @@
 static int
 moveto_attr_alldesc(struct lyxp_set *set, const struct lys_module *mod, const char *ncname)
 {
-    uint32_t i;
-    int replaced;
     struct lyd_meta *sub;
     struct lyxp_set *set_all_desc = NULL;
     LY_ERR rc;
@@ -5973,8 +5976,8 @@
     }
     lyxp_set_free(set_all_desc);
 
-    for (i = 0; i < set->used; ) {
-        replaced = 0;
+    for (uint32_t i = 0; i < set->used; ) {
+        uint8_t replaced = 0;
 
         /* only attributes of an elem can be in the result, skip all the rest,
          * we have all attributes qualified in lyd tree */
@@ -6023,7 +6026,7 @@
  */
 static LY_ERR
 moveto_self_add_children_r(const struct lyd_node *parent, uint32_t parent_pos, enum lyxp_node_type parent_type,
-        struct lyxp_set *to_set, const struct lyxp_set *dup_check_set, int options)
+        struct lyxp_set *to_set, const struct lyxp_set *dup_check_set, uint32_t options)
 {
     const struct lyd_node *iter, *first;
     LY_ERR rc;
@@ -6086,9 +6089,8 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-moveto_self(struct lyxp_set *set, int all_desc, int options)
+moveto_self(struct lyxp_set *set, uint8_t all_desc, uint32_t options)
 {
-    uint32_t i;
     struct lyxp_set ret_set;
     LY_ERR rc;
 
@@ -6108,7 +6110,7 @@
 
     /* add all the children, they get added recursively */
     set_init(&ret_set, set);
-    for (i = 0; i < set->used; ++i) {
+    for (uint32_t i = 0; i < set->used; ++i) {
         /* copy the current node to tmp */
         set_insert_node(&ret_set, set->val.nodes[i].node, set->val.nodes[i].pos, set->val.nodes[i].type, ret_set.used);
 
@@ -6145,10 +6147,10 @@
  * @return LY_ERR
  */
 static LY_ERR
-moveto_scnode_self(struct lyxp_set *set, int all_desc, int options)
+moveto_scnode_self(struct lyxp_set *set, uint8_t all_desc, uint32_t options)
 {
-    int getnext_opts;
-    uint32_t i, mod_idx;
+    uint32_t getnext_opts;
+    uint32_t mod_idx;
     const struct lysc_node *iter, *start_parent;
     const struct lys_module *mod;
 
@@ -6173,7 +6175,7 @@
     }
 
     /* add all the children, recursively as they are being added into the same set */
-    for (i = 0; i < set->used; ++i) {
+    for (uint32_t i = 0; i < set->used; ++i) {
         if (set->val.scnodes[i].in_ctx != 1) {
             if (set->val.scnodes[i].in_ctx != -2) {
                 continue;
@@ -6230,10 +6232,9 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-moveto_parent(struct lyxp_set *set, int all_desc, int options)
+moveto_parent(struct lyxp_set *set, uint8_t all_desc, uint32_t options)
 {
     LY_ERR rc;
-    uint32_t i;
     struct lyd_node *node, *new_node;
     enum lyxp_node_type new_type;
 
@@ -6252,7 +6253,7 @@
         LY_CHECK_RET(rc);
     }
 
-    for (i = 0; i < set->used; ++i) {
+    for (uint32_t i = 0; i < set->used; ++i) {
         node = set->val.nodes[i].node;
 
         if (set->val.nodes[i].type == LYXP_NODE_ELEM) {
@@ -6307,12 +6308,13 @@
  * @return LY_ERR
  */
 static LY_ERR
-moveto_scnode_parent(struct lyxp_set *set, int all_desc, int options)
+moveto_scnode_parent(struct lyxp_set *set, uint8_t all_desc, uint32_t options)
 {
-    int idx, i, orig_used, temp_ctx = 0;
+    int idx;
+    uint32_t i, orig_used;
+    uint8_t temp_ctx = 0;
     const struct lysc_node *node, *new_node;
     enum lyxp_node_type new_type;
-    LY_ERR rc;
 
     if (!set) {
         return LY_SUCCESS;
@@ -6325,8 +6327,7 @@
 
     if (all_desc) {
         /* <path>//.. == <path>//./.. */
-        rc = moveto_scnode_self(set, 1, options);
-        LY_CHECK_RET(rc);
+        LY_CHECK_RET(moveto_scnode_self(set, 1, options));
     }
 
     orig_used = set->used;
@@ -6361,7 +6362,8 @@
         }
 
         idx = lyxp_set_scnode_insert_node(set, new_node, new_type);
-        if ((idx < orig_used) && (idx > i)) {
+        LY_CHECK_RET(idx < 0, LY_EMEM);
+        if (((uint32_t)idx < orig_used) && ((uint32_t)idx > i)) {
             set->val.scnodes[idx].in_ctx = 2;
             temp_ctx = 1;
         }
@@ -6389,7 +6391,7 @@
  * @return LY_ERR
  */
 static LY_ERR
-moveto_op_comp(struct lyxp_set *set1, struct lyxp_set *set2, const char *op, int options)
+moveto_op_comp(struct lyxp_set *set1, struct lyxp_set *set2, const char *op, uint32_t options)
 {
     /*
      * NODE SET + NODE SET = NODE SET + STRING /(1 NODE SET) 2 STRING
@@ -6647,7 +6649,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, int options, int parent_pos_pred)
+eval_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, uint32_t options, uint8_t parent_pos_pred)
 {
     LY_ERR rc;
     uint16_t i, orig_exp;
@@ -6828,7 +6830,7 @@
     uint16_t key_count, e_idx, pred_idx = 0;
     const struct lysc_node *key;
     size_t pred_len;
-    int prev_lo;
+    uint32_t prev_lo;
     struct lyxp_expr *exp2 = NULL;
 
     assert(scnode->nodetype & (LYS_LIST | LYS_LEAFLIST));
@@ -6916,10 +6918,9 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_name_test_with_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, int attr_axis, int all_desc, struct lyxp_set *set,
-        int options)
+eval_name_test_with_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, uint8_t attr_axis, uint8_t all_desc, struct lyxp_set *set,
+        uint32_t options)
 {
-    int i;
     char *path;
     const char *ncname, *ncname_dict = NULL;
     uint16_t ncname_len;
@@ -6946,7 +6947,7 @@
 
     if (moveto_mod && !attr_axis && !all_desc && (set->type == LYXP_SET_NODE_SET)) {
         /* find the matching schema node in some parent in the context */
-        for (i = 0; i < (signed)set->used; ++i) {
+        for (uint32_t i = 0; i < set->used; ++i) {
             if (set->val.nodes[i].type == set->root_type) {
                 tmp = lys_find_child(NULL, moveto_mod, ncname, ncname_len, 0, 0);
             } else if ((set->val.nodes[i].type == LYXP_NODE_ELEM)
@@ -7004,6 +7005,8 @@
         }
     } else {
         if (set && (options & LYXP_SCNODE_ALL)) {
+            int64_t i;
+
             if (all_desc) {
                 rc = moveto_scnode_alldesc(set, moveto_mod, ncname_dict, options);
             } else {
@@ -7067,8 +7070,8 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_node_type_with_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, int attr_axis, int all_desc,
-        struct lyxp_set *set, int options)
+eval_node_type_with_predicate(struct lyxp_expr *exp, uint16_t *tok_idx, uint8_t attr_axis, uint8_t all_desc,
+        struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
 
@@ -7132,9 +7135,9 @@
  * @return LY_ERR (YL_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_relative_location_path(struct lyxp_expr *exp, uint16_t *tok_idx, int all_desc, struct lyxp_set *set, int options)
+eval_relative_location_path(struct lyxp_expr *exp, uint16_t *tok_idx, uint8_t all_desc, struct lyxp_set *set, uint32_t options)
 {
-    int attr_axis;
+    uint8_t attr_axis;
     LY_ERR rc;
 
     goto step;
@@ -7222,9 +7225,9 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_absolute_location_path(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, int options)
+eval_absolute_location_path(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, uint32_t options)
 {
-    int all_desc;
+    uint8_t all_desc;
     LY_ERR rc;
 
     if (set) {
@@ -7283,10 +7286,10 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_function_call(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, int options)
+eval_function_call(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
-    LY_ERR (*xpath_func)(struct lyxp_set **, uint16_t, struct lyxp_set *, int) = NULL;
+    LY_ERR (*xpath_func)(struct lyxp_set **, uint16_t, struct lyxp_set *, uint32_t) = NULL;
     uint16_t arg_count = 0, i;
     struct lyxp_set **args = NULL, **args_aux;
 
@@ -7547,9 +7550,9 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_path_expr(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, int options)
+eval_path_expr(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, uint32_t options)
 {
-    int all_desc, parent_pos_pred;
+    uint8_t all_desc, parent_pos_pred;
     LY_ERR rc;
 
     switch (exp->tokens[*tok_idx]) {
@@ -7681,7 +7684,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_union_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_union_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc = LY_SUCCESS;
     struct lyxp_set orig_set, set2;
@@ -7742,7 +7745,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_unary_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_unary_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     uint16_t this_op, i;
@@ -7790,7 +7793,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_multiplicative_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_multiplicative_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     uint16_t this_op;
@@ -7858,7 +7861,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_additive_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_additive_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     uint16_t this_op;
@@ -7928,7 +7931,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_relational_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_relational_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     uint16_t this_op;
@@ -7995,7 +7998,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_equality_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_equality_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     uint16_t this_op;
@@ -8063,7 +8066,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_and_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_and_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     struct lyxp_set orig_set, set2;
@@ -8133,7 +8136,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_or_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, int options)
+eval_or_expr(struct lyxp_expr *exp, uint16_t *tok_idx, uint16_t repeat, struct lyxp_set *set, uint32_t options)
 {
     LY_ERR rc;
     struct lyxp_set orig_set, set2;
@@ -8203,7 +8206,7 @@
  * @return LY_ERR (LY_EINCOMPLETE on unresolved when)
  */
 static LY_ERR
-eval_expr_select(struct lyxp_expr *exp, uint16_t *tok_idx, enum lyxp_expr_type etype, struct lyxp_set *set, int options)
+eval_expr_select(struct lyxp_expr *exp, uint16_t *tok_idx, enum lyxp_expr_type etype, struct lyxp_set *set, uint32_t options)
 {
     uint16_t i, count;
     enum lyxp_expr_type next_etype;
@@ -8271,7 +8274,7 @@
  * @return Root type.
  */
 static enum lyxp_node_type
-lyxp_get_root_type(const struct lyd_node *ctx_node, const struct lysc_node *ctx_scnode, int options)
+lyxp_get_root_type(const struct lyd_node *ctx_node, const struct lysc_node *ctx_scnode, uint32_t options)
 {
     const struct lysc_node *op;
 
@@ -8301,7 +8304,7 @@
 
 LY_ERR
 lyxp_eval(struct lyxp_expr *exp, LY_PREFIX_FORMAT format, const struct lys_module *local_mod, const struct lyd_node *ctx_node,
-        enum lyxp_node_type ctx_node_type, const struct lyd_node *tree, struct lyxp_set *set, int options)
+        enum lyxp_node_type ctx_node_type, const struct lyd_node *tree, struct lyxp_set *set, uint32_t options)
 {
     uint16_t tok_idx = 0;
     const struct lyd_node *real_ctx_node;
@@ -8570,7 +8573,7 @@
 
 LY_ERR
 lyxp_atomize(struct lyxp_expr *exp, LY_PREFIX_FORMAT format, const struct lys_module *local_mod,
-        const struct lysc_node *ctx_scnode, enum lyxp_node_type ctx_scnode_type, struct lyxp_set *set, int options)
+        const struct lysc_node *ctx_scnode, enum lyxp_node_type ctx_scnode_type, struct lyxp_set *set, uint32_t options)
 {
     struct ly_ctx *ctx;
     const struct lysc_node *real_ctx_scnode;
diff --git a/src/xpath.h b/src/xpath.h
index 1e8b3b2..a0d7c4a 100644
--- a/src/xpath.h
+++ b/src/xpath.h
@@ -238,7 +238,7 @@
         } *meta;
         char *str;
         long double num;
-        int bln;
+        uint8_t bln; /* boolean */
     } val;
 
     /* this is valid only for type LYXP_SET_NODE_SET and LYXP_SET_SCNODE_SET */
@@ -292,7 +292,7 @@
  */
 LY_ERR lyxp_eval(struct lyxp_expr *exp, LY_PREFIX_FORMAT format, const struct lys_module *local_mod,
         const struct lyd_node *ctx_node, enum lyxp_node_type ctx_node_type, const struct lyd_node *tree,
-        struct lyxp_set *set, int options);
+        struct lyxp_set *set, uint32_t options);
 
 #define LYXP_SCHEMA 0x01        /**< Apply data node access restrictions defined for 'when' and 'must' evaluation. */
 
@@ -312,7 +312,7 @@
  */
 LY_ERR lyxp_atomize(struct lyxp_expr *exp, LY_PREFIX_FORMAT format, const struct lys_module *local_mod,
         const struct lysc_node *ctx_scnode, enum lyxp_node_type ctx_scnode_type, struct lyxp_set *set,
-        int options);
+        uint32_t options);
 
 /* used only internally */
 #define LYXP_SCNODE_ALL 0x0E
@@ -377,7 +377,7 @@
  * information about expressions and their operators (fill repeat).
  * @return Filled expression structure or NULL on error.
  */
-struct lyxp_expr *lyxp_expr_parse(const struct ly_ctx *ctx, const char *expr, size_t expr_len, int reparse);
+struct lyxp_expr *lyxp_expr_parse(const struct ly_ctx *ctx, const char *expr, size_t expr_len, uint8_t reparse);
 
 /**
  * @brief Duplicate parsed XPath expression.
diff --git a/tests/utests/data/test_types.c b/tests/utests/data/test_types.c
index 900c9b2..ff4d20e 100644
--- a/tests/utests/data/test_types.c
+++ b/tests/utests/data/test_types.c
@@ -633,7 +633,7 @@
                    const struct lys_module *mod)
 {
     const char *str;
-    int dynamic;
+    uint8_t dynamic;
 
     assert_non_null(str = value->realtype->plugin->print(value, format, (void *)mod, &dynamic));
     assert_string_equal(expected_value, str);
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index efbd868..c8b3511 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -38,11 +38,11 @@
 
 LY_ERR buf_add_char(struct ly_ctx *ctx, struct ly_in *in, size_t len, char **buf, size_t *buf_len, size_t *buf_used);
 LY_ERR buf_store_char(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg, char **word_p,
-                      size_t *word_len, char **word_b, size_t *buf_len, int need_buf, int *prefix);
+                      size_t *word_len, char **word_b, size_t *buf_len, uint8_t need_buf, uint8_t *prefix);
 LY_ERR get_keyword(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt *kw, char **word_p, size_t *word_len);
 LY_ERR get_argument(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum yang_arg arg,
                     uint16_t *flags, char **word_p, char **word_b, size_t *word_len);
-LY_ERR skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, int comment);
+LY_ERR skip_comment(struct lys_yang_parser_ctx *ctx, struct ly_in *in, uint8_t comment);
 
 LY_ERR parse_action(struct lys_yang_parser_ctx *ctx, struct ly_in *in, struct lysp_node *parent, struct lysp_action **actions);
 LY_ERR parse_any(struct lys_yang_parser_ctx *ctx, struct ly_in *in, enum ly_stmt kw, struct lysp_node *parent, struct lysp_node **siblings);
@@ -143,7 +143,7 @@
     ctx.ctx = NULL;
     ctx.pos_type = LY_VLOG_LINE;
     ctx.line = 1;
-    int prefix = 0;
+    uint8_t prefix = 0;
 
     /* storing into buffer */
     in.current = "abcd";
@@ -190,9 +190,9 @@
 
     /* checking identifiers */
     assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, NULL));
-    logbuf_assert("Invalid identifier character ':'. Line number 1.");
+    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
     assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, '#', 1, NULL));
-    logbuf_assert("Invalid identifier first character '#'. Line number 1.");
+    logbuf_assert("Invalid identifier first character '#' (0x0023). Line number 1.");
 
     assert_int_equal(LY_SUCCESS, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, 'a', 1, &prefix));
     assert_int_equal(0, prefix);
@@ -204,7 +204,7 @@
     assert_int_equal(2, prefix);
     /* second colon is invalid */
     assert_int_equal(LY_EVALID, lysp_check_identifierchar((struct lys_parser_ctx *)&ctx, ':', 0, &prefix));
-    logbuf_assert("Invalid identifier character ':'. Line number 1.");
+    logbuf_assert("Invalid identifier character ':' (0x003a). Line number 1.");
 }
 
 static void
diff --git a/tests/utests/schema/test_parser_yin.c b/tests/utests/schema/test_parser_yin.c
index 201de0d..1d0f011 100644
--- a/tests/utests/schema/test_parser_yin.c
+++ b/tests/utests/schema/test_parser_yin.c
@@ -754,7 +754,7 @@
     st->yin_ctx->xmlctx->value = "#invalid";
     st->yin_ctx->xmlctx->value_len = 8;
     assert_int_equal(yin_validate_value(st->yin_ctx, Y_IDENTIF_ARG), LY_EVALID);
-    logbuf_assert("Invalid identifier character '#'. Line number 1.");
+    logbuf_assert("Invalid identifier character '#' (0x0023). Line number 1.");
 
     st->yin_ctx->xmlctx->value = "";
     st->yin_ctx->xmlctx->value_len = 0;
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index e587bc2..cf30cdc 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -30,7 +30,7 @@
 void yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx);
 
 LY_ERR lys_path_token(const char **path, const char **prefix, size_t *prefix_len, const char **name, size_t *name_len,
-                      int *parent_times, int *has_predicate);
+                      int32_t *parent_times, uint8_t *has_predicate);
 
 #define BUFSIZE 1024
 char logbuf[BUFSIZE] = {0};
@@ -204,7 +204,7 @@
     struct lysc_node_leaflist *ll;
     struct lysc_node_leaf *l;
     const char *dflt;
-    int dynamic;
+    uint8_t dynamic;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
@@ -1276,10 +1276,10 @@
     logbuf_assert("Duplicate identifier \"one\" of bit statement. Line number 1.");
     assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
                                    "bit '11';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier first character '1'. Line number 1.");
+    logbuf_assert("Invalid identifier first character '1' (0x0031). Line number 1.");
     assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module aa {namespace urn:aa;prefix aa; leaf l {type bits {"
                                    "bit 'x1$1';}}}", LYS_IN_YANG, &mod));
-    logbuf_assert("Invalid identifier character '$'. Line number 1.");
+    logbuf_assert("Invalid identifier character '$' (0x0024). Line number 1.");
 
     assert_int_equal(LY_EVALID, lys_parse_mem(ctx, "module bb {namespace urn:bb;prefix bb; leaf l {type bits;}}", LYS_IN_YANG, &mod));
     logbuf_assert("Missing bit substatement for bits type. /bb:l");
@@ -1519,7 +1519,8 @@
     struct lysc_type *type;
     const char *path, *name, *prefix;
     size_t prefix_len, name_len;
-    int parent_times, has_predicate;
+    int32_t parent_times;
+    uint8_t has_predicate;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
@@ -2016,7 +2017,7 @@
     const struct lys_module *mod;
     struct lysc_type *type;
     struct lysc_node_leaf *leaf;
-    int dynamic;
+    uint8_t dynamic;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
@@ -2357,7 +2358,7 @@
     struct lysc_node *parent, *child;
     struct lysc_node_leaf *leaf;
     struct lysc_node_leaflist *llist;
-    int dynamic;
+    uint8_t dynamic;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
@@ -2667,7 +2668,7 @@
     const struct lysc_node_leaflist *llist;
     const struct lysc_node_leaf *leaf;
     const char *str;
-    int dynamic;
+    uint8_t dynamic;
 
     assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, LY_CTX_DISABLE_SEARCHDIRS, &ctx));
 
diff --git a/tests/utests/test_context.c b/tests/utests/test_context.c
index 7fc369d..136663c 100644
--- a/tests/utests/test_context.c
+++ b/tests/utests/test_context.c
@@ -183,7 +183,7 @@
 
     struct ly_ctx *ctx;
 
-    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0xffffffff, &ctx));
+    assert_int_equal(LY_SUCCESS, ly_ctx_new(NULL, 0xffff, &ctx));
 
     /* invalid arguments */
     assert_int_equal(0, ly_ctx_get_options(NULL));
diff --git a/tests/utests/test_hash_table.c b/tests/utests/test_hash_table.c
index 12a946e..c9943ba 100644
--- a/tests/utests/test_hash_table.c
+++ b/tests/utests/test_hash_table.c
@@ -119,8 +119,8 @@
 #endif
 }
 
-static int
-ht_equal_clb(void *val1, void *val2, int mod, void *cb_data)
+static uint8_t
+ht_equal_clb(void *val1, void *val2, uint8_t mod, void *cb_data)
 {
     int *v1, *v2;
     (void)mod;