Skip to content

Commit

Permalink
Merge pull request #5247 from seanyeh/fix-dismiss-rename-segfault
Browse files Browse the repository at this point in the history
Add bounds checks for unit dismiss and recall (fixes #5171)
  • Loading branch information
Vultraz committed Oct 28, 2020
2 parents e43a0d8 + ee60606 commit 0919b0c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/gui/dialogs/unit_recall.cpp
Expand Up @@ -313,6 +313,10 @@ void unit_recall::rename_unit(window& window)
listbox& list = find_widget<listbox>(&window, "recall_list", false);

const int index = list.get_selected_row();
if (index == -1) {
return;
}

unit& selected_unit = const_cast<unit&>(*recall_list_[index].get());

std::string name = selected_unit.name();
Expand Down Expand Up @@ -343,6 +347,9 @@ void unit_recall::dismiss_unit(window& window)

listbox& list = find_widget<listbox>(&window, "recall_list", false);
const int index = list.get_selected_row();
if (index == -1) {
return;
}

const unit& u = *recall_list_[index].get();

Expand Down Expand Up @@ -464,6 +471,11 @@ void unit_recall::filter_text_changed(text_box_base* textbox, const std::string&
}

list.set_row_shown(show_items);

// Disable rename and dismiss buttons if no units are shown
const bool any_shown = list.any_rows_shown();
find_widget<button>(&window, "rename", false).set_active(any_shown);
find_widget<button>(&window, "dismiss", false).set_active(any_shown);
}

} // namespace dialogs
Expand Down

0 comments on commit 0919b0c

Please sign in to comment.