Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions dbcon/execplan/rewrites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,18 @@ execplan::ParseTree* newAndNode()
return new execplan::ParseTree(op);
}

template <typename T>
struct is_set : std::false_type
{
};

template <typename T, typename Compare, typename Alloc>
struct is_set<std::set<T, Compare, Alloc>> : std::true_type
{
};

template <typename Common>
execplan::ParseTree* appendToRoot(execplan::ParseTree* tree, const Common& common)
execplan::ParseTree* appendToRoot(execplan::ParseTree* tree, Common& common)
{
if (common.empty())
return tree;
Expand All @@ -230,7 +240,15 @@ execplan::ParseTree* appendToRoot(execplan::ParseTree* tree, const Common& commo
{
execplan::ParseTree* andCondition = *treenode;

++treenode;
// Increment or erase based on container type to avoid UB
if constexpr (is_set<Common>::value)
{
treenode = common.erase(treenode);
}
else
{
++treenode;
}
current->right(andCondition);

if ((treenode != common.end() && std::next(treenode) != common.end()) ||
Expand Down