Skip to content

Commit 5f20e92

Browse files
authored
union BUGFIX sort union with leafrefs (#2361)
An assert was being hit in lyplg_type_sort_union() when evaluating leafrefs due to not using the realtype node. Signed-off-by: Michal Vasko <[email protected]> Signed-off-by: Brad House <[email protected]>
1 parent 529a594 commit 5f20e92

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/plugins_types/union.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co
515515
int rc = LY_SUCCESS;
516516
LY_ARRAY_COUNT_TYPE u;
517517
struct lysc_type **types;
518+
struct lysc_type *type;
518519

519520
if (val1->subvalue->value.realtype == val2->subvalue->value.realtype) {
520521
return val1->subvalue->value.realtype->plugin->sort(ctx, &val1->subvalue->value, &val2->subvalue->value);
@@ -523,10 +524,16 @@ lyplg_type_sort_union(const struct ly_ctx *ctx, const struct lyd_value *val1, co
523524
/* compare according to the order of types */
524525
types = ((struct lysc_type_union *)val1->realtype)->types;
525526
LY_ARRAY_FOR(types, u) {
526-
if (types[u] == val1->subvalue->value.realtype) {
527+
if (types[u]->basetype == LY_TYPE_LEAFREF) {
528+
type = ((struct lysc_type_leafref *)types[u])->realtype;
529+
} else {
530+
type = types[u];
531+
}
532+
533+
if (type == val1->subvalue->value.realtype) {
527534
rc = 1;
528535
break;
529-
} else if (types[u] == val2->subvalue->value.realtype) {
536+
} else if (type == val2->subvalue->value.realtype) {
530537
rc = -1;
531538
break;
532539
}

0 commit comments

Comments
 (0)