libyang BUGFIX setting the return code
The return code should be initialized to LY_SUCCESS, and in the case
of an error, the error code should be explicitly set.
diff --git a/src/parser_xml.c b/src/parser_xml.c
index e7f3bbb..f237cdf 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -70,7 +70,7 @@
static LY_ERR
lydxml_metadata(struct lyd_xml_ctx *lydctx, struct lyd_meta **meta)
{
- LY_ERR ret = LY_EVALID;
+ LY_ERR ret = LY_SUCCESS;
const struct lyxml_ns *ns;
struct lys_module *mod;
const char *name;
@@ -84,6 +84,7 @@
/* in XML, all attributes must be prefixed
* TODO exception for NETCONF filters which are supposed to map to the ietf-netconf without prefix */
if (lydctx->parse_opts & LYD_PARSE_STRICT) {
+ ret = LY_EVALID;
LOGVAL(xmlctx->ctx, LYVE_REFERENCE, "Missing mandatory prefix for XML metadata \"%.*s\".",
(int)xmlctx->name_len, xmlctx->name);
goto cleanup;
@@ -99,6 +100,7 @@
/* get namespace of the attribute to find its annotation definition */
ns = lyxml_ns_get(&xmlctx->ns, xmlctx->prefix, xmlctx->prefix_len);
if (!ns) {
+ ret = LY_ENOTFOUND;
/* unknown namespace, XML error */
LOGVAL(xmlctx->ctx, LYVE_REFERENCE, "Unknown XML prefix \"%.*s\".", (int)xmlctx->prefix_len, xmlctx->prefix);
goto cleanup;
@@ -107,6 +109,7 @@
if (!mod) {
/* module is not implemented or not present in the schema */
if (lydctx->parse_opts & LYD_PARSE_STRICT) {
+ ret = LY_ENOTFOUND;
LOGVAL(xmlctx->ctx, LYVE_REFERENCE,
"Unknown (or not implemented) YANG module with namespace \"%s\" for metadata \"%.*s%s%.*s\".",
ns->uri, (int)xmlctx->prefix_len, xmlctx->prefix, xmlctx->prefix_len ? ":" : "",
@@ -131,8 +134,6 @@
LY_CHECK_GOTO(ret = lyxml_ctx_next(xmlctx), cleanup);
}
- ret = LY_SUCCESS;
-
cleanup:
if (ret) {
lyd_free_meta_siblings(*meta);
diff --git a/src/schema_compile.c b/src/schema_compile.c
index a525ece..51937e0 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -520,7 +520,7 @@
LY_ERR
lys_compile_extension_instance(struct lysc_ctx *ctx, const struct lysp_ext_instance *ext_p, struct lysc_ext_instance *ext)
{
- LY_ERR ret = LY_EVALID, r;
+ LY_ERR ret = LY_SUCCESS, r;
LY_ARRAY_COUNT_TYPE u;
struct lysp_stmt *stmt;
void *parsed = NULL, **compiled = NULL;
@@ -538,6 +538,7 @@
if (u == LY_ARRAY_COUNT(ext->substmts)) {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Invalid keyword \"%s\" as a child of \"%s%s%s\" extension instance.",
stmt->stmt, ext_p->name, ext_p->argument ? " " : "", ext_p->argument ? ext_p->argument : "");
+ ret = LY_EVALID;
goto cleanup;
}
}
@@ -590,6 +591,7 @@
/* single item */
if (*((const char **)ext->substmts[u].storage)) {
LOGVAL(ctx->ctx, LY_VCODE_DUPSTMT, stmt->stmt);
+ ret = LY_EVALID;
goto cleanup;
}
str_p = (const char **)ext->substmts[u].storage;
@@ -629,6 +631,7 @@
/* single item */
if (*(struct lysc_type **)ext->substmts[u].storage) {
LOGVAL(ctx->ctx, LY_VCODE_DUPSTMT, stmt->stmt);
+ ret = LY_EVALID;
goto cleanup;
}
compiled = ext->substmts[u].storage;
@@ -653,6 +656,7 @@
default:
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Statement \"%s\" is not supported as an extension (found in \"%s%s%s\") substatement.",
stmt->stmt, ext_p->name, ext_p->argument ? " " : "", ext_p->argument ? ext_p->argument : "");
+ ret = LY_EVALID;
goto cleanup;
}
}
@@ -661,12 +665,11 @@
if (((ext->substmts[u].cardinality == LY_STMT_CARD_MAND) || (ext->substmts[u].cardinality == LY_STMT_CARD_SOME)) && !stmt_counter) {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Missing mandatory keyword \"%s\" as a child of \"%s%s%s\".",
ly_stmt2str(ext->substmts[u].stmt), ext_p->name, ext_p->argument ? " " : "", ext_p->argument ? ext_p->argument : "");
+ ret = LY_EVALID;
goto cleanup;
}
}
- ret = LY_SUCCESS;
-
cleanup:
ctx->ext = NULL;
return ret;
diff --git a/src/schema_compile_node.c b/src/schema_compile_node.c
index 32f26fd..1092aee 100644
--- a/src/schema_compile_node.c
+++ b/src/schema_compile_node.c
@@ -606,7 +606,7 @@
lys_compile_type_range(struct lysc_ctx *ctx, struct lysp_restr *range_p, LY_DATA_TYPE basetype, ly_bool length_restr,
uint8_t frdigits, struct lysc_range *base_range, struct lysc_range **range)
{
- LY_ERR ret = LY_EVALID;
+ LY_ERR ret = LY_SUCCESS;
const char *expr;
struct lysc_range_part *parts = NULL, *part;
ly_bool range_expected = 0, uns;
@@ -624,11 +624,13 @@
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - unexpected end of the expression after \"..\" (%s).",
length_restr ? "length" : "range", range_p->arg);
+ ret = LY_EVALID;
goto cleanup;
} else if (!parts || (parts_done == LY_ARRAY_COUNT(parts))) {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - unexpected end of the expression (%s).",
length_restr ? "length" : "range", range_p->arg);
+ ret = LY_EVALID;
goto cleanup;
}
parts_done++;
@@ -639,17 +641,19 @@
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - unexpected data before min keyword (%.*s).", length_restr ? "length" : "range",
(int)(expr - range_p->arg.str), range_p->arg.str);
+ ret = LY_EVALID;
goto cleanup;
}
expr += ly_strlen_const("min");
LY_ARRAY_NEW_GOTO(ctx->ctx, parts, part, ret, cleanup);
- LY_CHECK_GOTO(range_part_minmax(ctx, part, 0, 0, basetype, 1, length_restr, frdigits, base_range, NULL), cleanup);
+ LY_CHECK_GOTO(ret = range_part_minmax(ctx, part, 0, 0, basetype, 1, length_restr, frdigits, base_range, NULL), cleanup);
part->max_64 = part->min_64;
} else if (*expr == '|') {
if (!parts || range_expected) {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - unexpected beginning of the expression (%s).", length_restr ? "length" : "range", expr);
+ ret = LY_EVALID;
goto cleanup;
}
expr++;
@@ -663,6 +667,7 @@
if (!parts || (LY_ARRAY_COUNT(parts) == parts_done)) {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - unexpected \"..\" without a lower bound.", length_restr ? "length" : "range");
+ ret = LY_EVALID;
goto cleanup;
}
/* continue expecting the upper boundary */
@@ -671,11 +676,11 @@
/* number */
if (range_expected) {
part = &parts[LY_ARRAY_COUNT(parts) - 1];
- LY_CHECK_GOTO(range_part_minmax(ctx, part, 1, part->min_64, basetype, 0, length_restr, frdigits, NULL, &expr), cleanup);
+ LY_CHECK_GOTO(ret = range_part_minmax(ctx, part, 1, part->min_64, basetype, 0, length_restr, frdigits, NULL, &expr), cleanup);
range_expected = 0;
} else {
LY_ARRAY_NEW_GOTO(ctx->ctx, parts, part, ret, cleanup);
- LY_CHECK_GOTO(range_part_minmax(ctx, part, 0, parts_done ? parts[LY_ARRAY_COUNT(parts) - 2].max_64 : 0,
+ LY_CHECK_GOTO(ret = range_part_minmax(ctx, part, 0, parts_done ? parts[LY_ARRAY_COUNT(parts) - 2].max_64 : 0,
basetype, parts_done ? 0 : 1, length_restr, frdigits, NULL, &expr), cleanup);
part->max_64 = part->min_64;
}
@@ -689,21 +694,23 @@
if (*expr != '\0') {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Invalid %s restriction - unexpected data after max keyword (%s).",
length_restr ? "length" : "range", expr);
+ ret = LY_EVALID;
goto cleanup;
}
if (range_expected) {
part = &parts[LY_ARRAY_COUNT(parts) - 1];
- LY_CHECK_GOTO(range_part_minmax(ctx, part, 1, part->min_64, basetype, 0, length_restr, frdigits, base_range, NULL), cleanup);
+ LY_CHECK_GOTO(ret = range_part_minmax(ctx, part, 1, part->min_64, basetype, 0, length_restr, frdigits, base_range, NULL), cleanup);
range_expected = 0;
} else {
LY_ARRAY_NEW_GOTO(ctx->ctx, parts, part, ret, cleanup);
- LY_CHECK_GOTO(range_part_minmax(ctx, part, 1, parts_done ? parts[LY_ARRAY_COUNT(parts) - 2].max_64 : 0,
+ LY_CHECK_GOTO(ret = range_part_minmax(ctx, part, 1, parts_done ? parts[LY_ARRAY_COUNT(parts) - 2].max_64 : 0,
basetype, parts_done ? 0 : 1, length_restr, frdigits, base_range, NULL), cleanup);
part->min_64 = part->max_64;
}
} else {
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG, "Invalid %s restriction - unexpected data (%s).",
length_restr ? "length" : "range", expr);
+ ret = LY_EVALID;
goto cleanup;
}
}
@@ -793,6 +800,7 @@
LOGVAL(ctx->ctx, LYVE_SYNTAX_YANG,
"Invalid %s restriction - the derived restriction (%s) is not equally or more limiting.",
length_restr ? "length" : "range", range_p->arg);
+ ret = LY_EVALID;
goto cleanup;
}
}
@@ -823,7 +831,6 @@
(*range)->parts = parts;
parts = NULL;
- ret = LY_SUCCESS;
cleanup:
LY_ARRAY_FREE(parts);