confd: lyx: Allow diffs of NULL nodes

This makes the pattern

    if (lydx_get_diff(lydx_get_child(diffnode, "attribute"), &nd)) {
        /* Handle changes to "attribute" */
    }

safe to use in the common case where "attribute" has not been
modified, and is therefore not present in `diffnode`.
This commit is contained in:
Tobias Waldekranz
2023-06-01 15:16:39 +02:00
parent 092db20a80
commit 258ba272c7
+4
View File
@@ -41,6 +41,9 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd)
memset(nd, 0, sizeof(*nd));
if (!node)
goto out;
nd->op = lydx_get_op(node);
nd->val = lyd_get_value(node);
@@ -69,6 +72,7 @@ bool lydx_get_diff(struct lyd_node *node, struct lydx_diff *nd)
(nd->old && !nd->was_default) ||
(nd->new && !nd->is_default);
out:
return nd->modified;
}