Skip to content

Commit d4b8282

Browse files
committed
tree UPDATE minor improvements
1 parent dbe228e commit d4b8282

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/tree_data_new.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,9 @@ LIBYANG_API_DEF LY_ERR
589589
lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys,
590590
uint32_t options, struct lyd_node **node)
591591
{
592+
LY_ERR r;
592593
struct lyd_node *ret = NULL;
593-
const struct lysc_node *schema;
594+
const struct lysc_node *schema = NULL;
594595
struct lysc_ext_instance *ext = NULL;
595596
const struct ly_ctx *ctx = parent ? LYD_CTX(parent) : (module ? module->ctx : NULL);
596597
uint32_t getnext_opts = (options & LYD_NEW_VAL_OUTPUT) ? LYS_GETNEXT_OUTPUT : 0;
@@ -606,11 +607,12 @@ lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const ch
606607
}
607608

608609
/* find schema node */
609-
schema = lys_find_child(ctx, parent ? parent->schema : NULL, module, NULL, 0, name, 0, getnext_opts);
610-
if (schema && (schema->nodetype != LYS_LIST)) {
611-
schema = NULL;
610+
r = lys_find_child_node(ctx, parent ? parent->schema : NULL, module, NULL, 0, 0, NULL, name, 0, getnext_opts,
611+
&schema, &ext);
612+
if (!r && (schema->nodetype != LYS_LIST)) {
613+
r = LY_ENOT;
612614
}
613-
LY_CHECK_ERR_RET(!schema, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), LY_ENOTFOUND);
615+
LY_CHECK_ERR_RET(r, LOGERR(ctx, LY_EINVAL, "List node \"%s\" not found.", name), LY_ENOTFOUND);
614616

615617
if ((schema->flags & LYS_KEYLESS) && !keys[0]) {
616618
/* key-less list */

src/tree_schema.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ lys_find_child_node(const struct ly_ctx *ctx, const struct lysc_node *parent, co
544544
{
545545
const struct lysc_node *node = NULL;
546546

547+
assert(name);
548+
547549
*snode = NULL;
548550
if (ext) {
549551
*ext = NULL;
@@ -552,7 +554,7 @@ lys_find_child_node(const struct ly_ctx *ctx, const struct lysc_node *parent, co
552554
if (prefix && !prefix_len) {
553555
prefix_len = strlen(prefix);
554556
}
555-
if (name && !name_len) {
557+
if (!name_len) {
556558
name_len = strlen(name);
557559
}
558560

@@ -603,7 +605,7 @@ lys_find_child(const struct ly_ctx *ctx, const struct lysc_node *parent, const s
603605
if (mod_name && !mod_len) {
604606
mod_len = strlen(mod_name);
605607
}
606-
if (name && !name_len) {
608+
if (!name_len) {
607609
name_len = strlen(name);
608610
}
609611

0 commit comments

Comments
 (0)