From 258ba272c724d6066d6fa3c6a2c0873c18ef9693 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 31 May 2023 10:47:27 +0200 Subject: [PATCH] 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`. --- src/confd/src/lyx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/confd/src/lyx.c b/src/confd/src/lyx.c index 5590c343..413f3dc3 100644 --- a/src/confd/src/lyx.c +++ b/src/confd/src/lyx.c @@ -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; }