Skip to content

Commit d18e6df

Browse files
author
roman
committed
printer context BUGFIX struct ext handling
1 parent 6178f9a commit d18e6df

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

src/printer_context.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ctxs_exts(const struct lysc_ext_instance *exts, struct ly_ht *ht, int *size)
121121
ctxs_exts(exts[u].exts, ht, size);
122122

123123
/* substmts */
124-
*size += sizeof(LY_ARRAY_COUNT_TYPE) + LY_ARRAY_COUNT(exts[u].substmts) * sizeof *exts[u].substmts;
124+
*size += CTXS_SIZED_ARRAY(exts[u].substmts);
125125

126126
/* compiled, substmts storage */
127127
ext = lysc_get_ext_plugin(exts[u].def->plugin);
@@ -591,6 +591,11 @@ ly_ctx_compiled_ext_stmts_storage_size(const struct lysc_ext_substmt *substmts,
591591
const struct lysc_node *node;
592592

593593
LY_ARRAY_FOR(substmts, u) {
594+
if (!substmts[u].storage_p) {
595+
/* nothing is compiled */
596+
continue;
597+
}
598+
594599
switch (substmts[u].stmt) {
595600
case LY_STMT_NOTIFICATION:
596601
case LY_STMT_INPUT:
@@ -1775,10 +1780,17 @@ ly_ctx_compiled_ext_stmts_storage_print(const struct lysc_ext_substmt *orig_subs
17751780
{
17761781
LY_ERR rc = LY_SUCCESS;
17771782
LY_ARRAY_COUNT_TYPE u, v;
1783+
uint32_t hash;
1784+
const struct lysc_node *node;
17781785

17791786
LY_ARRAY_FOR(orig_substmts, u) {
17801787
assert(orig_substmts[u].stmt == substmts[u].stmt);
17811788

1789+
if (!orig_substmts[u].storage_p) {
1790+
/* nothing is compiled */
1791+
continue;
1792+
}
1793+
17821794
switch (orig_substmts[u].stmt) {
17831795
case LY_STMT_NOTIFICATION:
17841796
case LY_STMT_INPUT:
@@ -1794,7 +1806,15 @@ ly_ctx_compiled_ext_stmts_storage_print(const struct lysc_ext_substmt *orig_subs
17941806
case LY_STMT_LEAF_LIST:
17951807
case LY_STMT_LIST:
17961808
case LY_STMT_USES:
1797-
ctxp_children(*orig_substmts[u].storage_p, (struct lysc_node **)substmts[u].storage_p, addr_ht, ptr_set, mem);
1809+
node = *(const struct lysc_node **)orig_substmts[u].storage_p;
1810+
1811+
/* ht check, make sure the node list is stored only once */
1812+
hash = lyht_hash((const char *)&node, sizeof node);
1813+
if (lyht_insert(addr_ht, &node, hash, NULL) == LY_EEXIST) {
1814+
break;
1815+
}
1816+
1817+
ctxp_children(node, (struct lysc_node **)substmts[u].storage_p, addr_ht, ptr_set, mem);
17981818
break;
17991819
case LY_STMT_ARGUMENT:
18001820
case LY_STMT_CONTACT:

0 commit comments

Comments
 (0)