cellSaveData/overlays: prevent possible array out of bounds in list view

This commit is contained in:
Megamouse 2019-08-25 08:06:56 +02:00
parent eed32cf3a4
commit 32b5b11a83
3 changed files with 24 additions and 3 deletions

View File

@ -208,6 +208,12 @@ static error_code select_and_delete(ppu_thread& ppu)
save_entries.erase(save_entries.cbegin() + selected);
selected = -1;
// Reset the focused index if the new list is empty
if (save_entries.empty())
{
focused = -1;
}
// Display success message (return value should be irrelevant here)
msg = "Successfully removed entry!\n\n" + info;
cellSaveData.success("%s", msg);

View File

@ -56,7 +56,19 @@ namespace rsx
void list_view::update_selection()
{
auto current_element = m_items[m_selected_entry * 2].get();
if (m_selected_entry < 0)
{
return; // Ideally unreachable but it should still be possible to recover by user interaction.
}
const size_t current_index = static_cast<size_t>(m_selected_entry) * 2;
if (m_items.size() <= current_index)
{
return; // Ideally unreachable but it should still be possible to recover by user interaction.
}
auto current_element = m_items[current_index].get();
// Calculate bounds
auto min_y = current_element->y - y;

View File

@ -240,8 +240,11 @@ namespace rsx
m_no_saves = true;
m_list->set_cancel_only(true);
}
m_list->select_entry(focused);
else
{
// Only select an entry if there are entries available
m_list->select_entry(focused);
}
static_cast<label*>(m_description.get())->auto_resize();