]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
zone-tree: bugfix: iterating two trees when first empty
authorLibor Peltan <libor.peltan@nic.cz>
Wed, 29 Dec 2021 17:59:44 +0000 (18:59 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Thu, 6 Jan 2022 12:15:42 +0000 (13:15 +0100)
src/knot/zone/zone-tree.c

index 275f5069c0d2a84e742d2bdff5c3d9fadd3e8294..87dde1878459dde5b358a2d1557515f0921c155a 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2022 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -351,9 +351,16 @@ int zone_tree_it_double_begin(zone_tree_t *first, zone_tree_t *second, zone_tree
                if (it->it == NULL) {
                        return KNOT_ENOMEM;
                }
-               it->tree = first;
-               it->binode_second = ((first->flags & ZONE_TREE_BINO_SECOND) ? 1 : 0);
-               it->next_tree = second;
+               if (trie_it_finished(it->it) && second != NULL) { // first tree is empty
+                       trie_it_free(it->it);
+                       it->it = trie_it_begin(second->trie);
+                       it->tree = second;
+                       it->next_tree = NULL;
+               } else {
+                       it->tree = first;
+                       it->next_tree = second;
+               }
+               it->binode_second = ((it->tree->flags & ZONE_TREE_BINO_SECOND) ? 1 : 0);
        }
        return KNOT_EOK;
 }