data tree CHANGE make lyd_set_add() check for duplication to behave more like set
diff --git a/src/tree_data.c b/src/tree_data.c
index 95eb896..fa95850 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -1242,13 +1242,22 @@
API int
lyd_set_add(struct lyd_set *set, struct lyd_node *node)
{
+ unsigned int i;
struct lyd_node **new;
- if (!set) {
+ if (!set || !node) {
ly_errno = LY_EINVAL;
return EXIT_FAILURE;
}
+ /* search for duplication */
+ for (i = 0; i < set->number; i++) {
+ if (set->set[i] == node) {
+ /* already in set */
+ return EXIT_SUCCESS;
+ }
+ }
+
if (set->size == set->number) {
new = realloc(set->set, (set->size + 8) * sizeof *(set->set));
if (!new) {