Skip to content

Commit 93b9b24

Browse files
committed
schema compile BUGFIX disabled list unique node
Fixes #2202
1 parent 8ef803c commit 93b9b24

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

src/schema_compile.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,49 @@ lys_compile_unres_depset_implement(struct ly_ctx *ctx, struct lys_glob_unres *un
12081208
return LY_SUCCESS;
12091209
}
12101210

1211+
/**
1212+
* @brief Check that a disabled node (to be freed) can be freed and is not referenced.
1213+
*
1214+
* @param[in] node Disabled node to check.
1215+
* @return LY_ERR value.
1216+
*/
1217+
static LY_ERR
1218+
lys_compile_unres_check_disabled(const struct lysc_node *node)
1219+
{
1220+
const struct lysc_node *parent;
1221+
const struct lysc_node_list *slist;
1222+
LY_ARRAY_COUNT_TYPE u, v;
1223+
1224+
if (node->flags & LYS_KEY) {
1225+
LOG_LOCSET(node, NULL);
1226+
LOGVAL(node->module->ctx, LYVE_REFERENCE, "Key \"%s\" is disabled.", node->name);
1227+
LOG_LOCBACK(1, 0);
1228+
return LY_EVALID;
1229+
}
1230+
1231+
for (parent = node->parent; parent; parent = parent->parent) {
1232+
if (parent->nodetype != LYS_LIST) {
1233+
continue;
1234+
}
1235+
1236+
/* check list uniques */
1237+
slist = (struct lysc_node_list *)parent;
1238+
LY_ARRAY_FOR(slist->uniques, u) {
1239+
LY_ARRAY_FOR(slist->uniques[u], v) {
1240+
if (slist->uniques[u][v] == (struct lysc_node_leaf *)node) {
1241+
LOG_LOCSET(node, NULL);
1242+
LOGVAL(node->module->ctx, LYVE_REFERENCE, "Disabled node \"%s\" is referenced as unique in the list \"%s\".",
1243+
node->name, slist->name);
1244+
LOG_LOCBACK(1, 0);
1245+
return LY_EVALID;
1246+
}
1247+
}
1248+
}
1249+
}
1250+
1251+
return LY_SUCCESS;
1252+
}
1253+
12111254
/**
12121255
* @brief Finish dependency set compilation by resolving all the unres sets.
12131256
*
@@ -1365,13 +1408,9 @@ lys_compile_unres_depset(struct ly_ctx *ctx, struct lys_glob_unres *unres)
13651408
/* finally, remove all disabled nodes */
13661409
for (i = 0; i < ds_unres->disabled.count; ++i) {
13671410
node = ds_unres->disabled.snodes[i];
1368-
if (node->flags & LYS_KEY) {
1369-
LOG_LOCSET(node, NULL);
1370-
LOGVAL(ctx, LYVE_REFERENCE, "Key \"%s\" is disabled.", node->name);
1371-
LOG_LOCBACK(1, 0);
1372-
ret = LY_EVALID;
1373-
goto cleanup;
1374-
}
1411+
ret = lys_compile_unres_check_disabled(node);
1412+
LY_CHECK_GOTO(ret, cleanup);
1413+
13751414
LYSC_CTX_INIT_PMOD(cctx, node->module->parsed, NULL);
13761415

13771416
lysc_node_free(&cctx.free_ctx, node, 1);

0 commit comments

Comments
 (0)