libyang MAINTENANCE asserts added for coverity
diff --git a/src/common.c b/src/common.c
index 1e7e107..7bb05cf 100644
--- a/src/common.c
+++ b/src/common.c
@@ -1015,7 +1015,8 @@
node2 = node;
while (k) {
node2 = lys_parent(node2);
- if (!node2 || (node2->nodetype != LYS_USES)) {
+ assert(node2);
+ if (node2->nodetype != LYS_USES) {
--k;
}
}
diff --git a/src/parser_json.c b/src/parser_json.c
index 88c56fd..019d73a 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -1001,7 +1001,8 @@
result->parent = *parent;
diter = NULL;
if (schema->nodetype == LYS_LEAF && lys_is_key((struct lys_node_leaf *)schema, &pos)) {
- /* it is key and we need to insert it into a correct place */
+ /* it is key and we need to insert it into a correct place (we must have parent then, a key cannot be top-level) */
+ assert(*parent);
for (i = 0, diter = (*parent)->child;
diter && i < pos && diter->schema->nodetype == LYS_LEAF && lys_is_key((struct lys_node_leaf *)diter->schema, NULL);
i++, diter = diter->next);
diff --git a/src/parser_xml.c b/src/parser_xml.c
index 9335460..d186eca 100644
--- a/src/parser_xml.c
+++ b/src/parser_xml.c
@@ -250,7 +250,8 @@
(*result)->parent = parent;
diter = NULL;
if (schema->nodetype == LYS_LEAF && lys_is_key((struct lys_node_leaf *)schema, &pos)) {
- /* it is key and we need to insert it into a correct place */
+ /* it is key and we need to insert it into a correct place (a key must have a parent list) */
+ assert(parent);
for (i = 0, diter = parent->child;
diter && i < pos && diter->schema->nodetype == LYS_LEAF && lys_is_key((struct lys_node_leaf *)diter->schema, NULL);
i++, diter = diter->next);