Skip to content

Commit

Permalink
fix paring heap UB
Browse files Browse the repository at this point in the history
  • Loading branch information
jere8184 committed Jan 24, 2025
1 parent 6d9d8d7 commit 73ae0c8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions libopenage/datastructure/pairing_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ class PairingHeap final {
* erase all elements on the heap.
*/
void clear() {
auto delete_node = [](element_t node) { delete node; };
auto delete_node = [](element_t& node) { delete node; node = nullptr; };
this->iter_all<true>(delete_node);
this->root_node = nullptr;
this->node_count = 0;
Expand Down Expand Up @@ -586,7 +586,7 @@ class PairingHeap final {
* @param func Function to apply to each node.
*/
template <bool reverse = false>
void iter_all(const std::function<void(const element_t &)> &func) const {
void iter_all(const std::function<void(element_t &)> &func) {
this->walk_tree<reverse>(this->root_node, func);
}

Expand All @@ -599,21 +599,18 @@ class PairingHeap final {
* @param func Function to apply to each node.
*/
template <bool reverse = false>
void walk_tree(const element_t &start,
const std::function<void(const element_t &)> &func) const {
void walk_tree(element_t &start,
const std::function<void(element_t &)> &func) {
if constexpr (not reverse) {
func(start);
}

if (start) {
auto node = start->first_child;
while (true) {
if (not node) {
break;
}

while (node) {
this->walk_tree<reverse>(node, func);
node = node->next_sibling;
if(node)
node = node->next_sibling;
}
if constexpr (reverse) {
func(start);
Expand Down

0 comments on commit 73ae0c8

Please sign in to comment.