libyang BUGFIX return value checking
diff --git a/src/plugins_types.c b/src/plugins_types.c
index df9d5cd..f61bdc2 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -119,7 +119,7 @@
{
struct ly_set *ns_list = data;
- ly_set_add(ns_list, (void *)mod, 0, NULL);
+ LY_CHECK_RET(ly_set_add(ns_list, (void *)mod, 0, NULL), NULL);
return mod->prefix;
}
diff --git a/src/printer_json.c b/src/printer_json.c
index 0f77615..3abb3e8 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -90,14 +90,17 @@
*
* @param[in] ctx JSON printer context.
* @param[in] node First node of the array.
+ * @return LY_ERR value.
*/
-static void
+static LY_ERR
json_print_array_open(struct jsonpr_ctx *ctx, const struct lyd_node *node)
{
/* leaf-list's content is always printed on a single line */
ly_print_(ctx->out, "[%s", (!node->schema || node->schema->nodetype != LYS_LEAFLIST) && DO_FORMAT ? "\n" : "");
- ly_set_add(&ctx->open, (void *)node, 0, NULL);
+ LY_CHECK_RET(ly_set_add(&ctx->open, (void *)node, 0, NULL));
LEVEL_INC;
+
+ return LY_SUCCESS;
}
/**
@@ -661,7 +664,7 @@
{
if (!is_open_array(ctx, node)) {
LY_CHECK_RET(json_print_member(ctx, node, 0));
- json_print_array_open(ctx, node);
+ LY_CHECK_RET(json_print_array_open(ctx, node));
} else if (node->schema->nodetype == LYS_LEAFLIST) {
ly_print_(ctx->out, ",");
}
@@ -766,7 +769,7 @@
LY_CHECK_RET(json_print_member2(ctx, node->parent, node->format, &node->prefix, node->name, 0));
if (node->hint & LYD_NODE_OPAQ_ISLIST) {
- json_print_array_open(ctx, (struct lyd_node *)node);
+ LY_CHECK_RET(json_print_array_open(ctx, (struct lyd_node *)node));
LEVEL_INC;
}
}
diff --git a/src/tree_schema.c b/src/tree_schema.c
index 1ec681a..a4f81e3 100644
--- a/src/tree_schema.c
+++ b/src/tree_schema.c
@@ -554,6 +554,7 @@
static LY_ERR
lys_feature_change(const struct lys_module *mod, const char *name, uint8_t value, uint8_t skip_checks)
{
+ LY_ERR ret = LY_SUCCESS;
uint8_t all = 0;
LY_ARRAY_COUNT_TYPE u, disabled_count;
uint32_t changed_count;
@@ -594,8 +595,7 @@
continue;
} else {
/* feature already set correctly */
- ly_set_free(changed, NULL);
- return LY_SUCCESS;
+ goto cleanup;
}
}
@@ -611,8 +611,8 @@
LOGERR(ctx, LY_EDENIED,
"Feature \"%s\" cannot be enabled since it is disabled by its if-feature condition(s).",
f->name);
- ly_set_free(changed, NULL);
- return LY_EDENIED;
+ ret = LY_EDENIED;
+ goto cleanup;
}
}
}
@@ -625,7 +625,8 @@
}
/* remember the changed feature */
- LY_CHECK_RET(ly_set_add(changed, f, LY_SET_OPT_USEASLIST, NULL));
+ ret = ly_set_add(changed, f, LY_SET_OPT_USEASLIST, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
if (!all) {
/* stop in case changing a single feature */
@@ -638,8 +639,8 @@
if (!all && !changed->count) {
LOGERR(ctx, LY_EINVAL, "Feature \"%s\" not found in module \"%s\".", name, mod->name);
- ly_set_free(changed, NULL);
- return LY_ENOTFOUND;
+ ret = LY_ENOTFOUND;
+ goto cleanup;
}
if (value && all && disabled_count) {
@@ -661,8 +662,8 @@
f->flags &= ~LYS_FENABLED;
}
- ly_set_free(changed, NULL);
- return LY_EDENIED;
+ ret = LY_EDENIED;
+ goto cleanup;
} else {
/* we did some change in last run, try it again */
changed_count = changed->count;
@@ -687,15 +688,17 @@
/* the feature must be disabled now */
(*df)->flags &= ~LYS_FENABLED;
/* add the feature into the list of changed features */
- LY_CHECK_RET(ly_set_add(changed, *df, LY_SET_OPT_USEASLIST, NULL));
+ ret = ly_set_add(changed, *df, LY_SET_OPT_USEASLIST, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
break;
}
}
}
}
+cleanup:
ly_set_free(changed, NULL);
- return LY_SUCCESS;
+ return ret;
}
API LY_ERR
diff --git a/src/validation.c b/src/validation.c
index c16928d..e06df09 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -689,7 +689,8 @@
LY_CHECK_RET(ly_set_new(&set));
LY_LIST_FOR(first, diter) {
if (diter->schema == snode) {
- LY_CHECK_RET(ly_set_add(set, (void *)diter, LY_SET_OPT_USEASLIST, NULL));
+ ret = ly_set_add(set, (void *)diter, LY_SET_OPT_USEASLIST, NULL);
+ LY_CHECK_GOTO(ret, cleanup);
}
}
diff --git a/src/xpath.c b/src/xpath.c
index 8f96c45..ea436e4 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -5290,22 +5290,25 @@
*
* @param[in,out] set Set to use.
* @param[in] options Xpath options.
+ * @return LY_ERR value.
*/
-static void
+static LY_ERR
moveto_root(struct lyxp_set *set, uint32_t options)
{
if (!set) {
- return;
+ return LY_SUCCESS;
}
if (options & LYXP_SCNODE_ALL) {
set_scnode_clear_ctx(set);
- lyxp_set_scnode_insert_node(set, NULL, set->root_type, NULL);
+ LY_CHECK_RET(lyxp_set_scnode_insert_node(set, NULL, set->root_type, NULL));
} else {
set->type = LYXP_SET_NODE_SET;
set->used = 0;
set_insert_node(set, NULL, 0, set->root_type, 0);
}
+
+ return LY_SUCCESS;
}
/**
@@ -7237,11 +7240,10 @@
eval_absolute_location_path(struct lyxp_expr *exp, uint16_t *tok_idx, struct lyxp_set *set, uint32_t options)
{
uint8_t all_desc;
- LY_ERR rc;
if (set) {
/* no matter what tokens follow, we need to be at the root */
- moveto_root(set, options);
+ LY_CHECK_RET(moveto_root(set, options));
}
/* '/' RelativeLocationPath? */
@@ -7261,8 +7263,7 @@
case LYXP_TOKEN_AT:
case LYXP_TOKEN_NAMETEST:
case LYXP_TOKEN_NODETYPE:
- rc = eval_relative_location_path(exp, tok_idx, all_desc, set, options);
- LY_CHECK_RET(rc);
+ LY_CHECK_RET(eval_relative_location_path(exp, tok_idx, all_desc, set, options));
break;
default:
break;
@@ -7276,8 +7277,7 @@
lyxp_print_token(exp->tokens[*tok_idx]), exp->tok_pos[*tok_idx]);
++(*tok_idx);
- rc = eval_relative_location_path(exp, tok_idx, all_desc, set, options);
- LY_CHECK_RET(rc);
+ LY_CHECK_RET(eval_relative_location_path(exp, tok_idx, all_desc, set, options));
}
return LY_SUCCESS;