Skip to content

Commit

Permalink
Prevent infinite loop in Tree incremental search
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jul 20, 2020
1 parent d14932a commit c047949
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3419,6 +3419,8 @@ void Tree::scroll_to_item(TreeItem *p_item) {

TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_col, bool p_selectable, bool p_backwards) {
TreeItem *from = p_at;
TreeItem *loop = nullptr; // Safe-guard against infinite loop.

while (p_at) {
for (int i = 0; i < columns.size(); i++) {
if (p_at->get_text(i).findn(p_find) == 0 && (!p_selectable || p_at->is_selectable(i))) {
Expand All @@ -3438,6 +3440,12 @@ TreeItem *Tree::_search_item_text(TreeItem *p_at, const String &p_find, int *r_c
if ((p_at) == from) {
break;
}

if (!loop) {
loop = p_at;
} else if (loop == p_at) {
break;
}
}

return nullptr;
Expand Down

0 comments on commit c047949

Please sign in to comment.