Skip to content

Commit

Permalink
Fixed crashes on empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
mickelson committed Oct 16, 2014
1 parent 353980c commit 63c3af4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/fe_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,9 @@ void FeRomList::save_tags() const

bool FeRomList::set_fav( int idx, bool fav )
{
if (( idx < 0 ) || ( idx >= (int)m_list.size() ))
return false;

m_list[idx].set_info( FeRomInfo::Favourite, fav ? "1" : "" );
m_fav_changed=true;

Expand All @@ -1150,6 +1153,9 @@ bool FeRomList::set_fav( int idx, bool fav )
void FeRomList::get_tags_list( int idx,
std::vector< std::pair<std::string, bool> > &tags_list ) const
{
if (( idx < 0 ) || ( idx >= (int)m_list.size() ))
return;

std::string curr_tags = m_list[idx].get_info(FeRomInfo::Tags);

std::set<std::string> my_set;
Expand All @@ -1175,6 +1181,9 @@ void FeRomList::get_tags_list( int idx,

bool FeRomList::set_tag( int idx, const std::string &tag, bool flag )
{
if (( idx < 0 ) || ( idx >= (int)m_list.size() ))
return false;

std::string curr_tags = m_list[idx].get_info(FeRomInfo::Tags);
size_t pos = curr_tags.find( FE_TAGS_SEP + tag + FE_TAGS_SEP );

Expand Down
16 changes: 10 additions & 6 deletions src/fe_present.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,19 @@ bool FePresent::handle_event( FeInputMap::Command c,

case FeInputMap::RandomGame:
{
int step = rand() % m_feSettings->get_current_list_size();
if ( step != 0 )
int ls = m_feSettings->get_current_list_size();
if ( ls > 0 )
{
m_vm->on_transition( ToNewSelection, step );
int step = rand() % ls;
if ( step != 0 )
{
m_vm->on_transition( ToNewSelection, step );

m_feSettings->change_rom( step );
update( false );
m_feSettings->change_rom( step );
update( false );

m_vm->on_transition( FromOldSelection, -step );
m_vm->on_transition( FromOldSelection, -step );
}
}
}
break;
Expand Down
12 changes: 9 additions & 3 deletions src/fe_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,14 +648,14 @@ const std::string &FeSettings::get_current_list_title() const

const std::string &FeSettings::get_rom_info( int offset, FeRomInfo::Index index ) const
{
if ( m_rl.empty() )
return FE_EMPTY_STRING;

return get_rom_info_absolute( get_rom_index( offset ), index );
}

const std::string &FeSettings::get_rom_info_absolute( int pos, FeRomInfo::Index index ) const
{
if ( m_rl.empty() )
return FE_EMPTY_STRING;

return m_rl[pos].get_info( index );
}

Expand Down Expand Up @@ -902,6 +902,9 @@ bool FeSettings::select_last_launch()

bool FeSettings::get_current_fav() const
{
if ( m_rl.empty() )
return false;

const std::string &s = m_rl[get_rom_index()].get_info(FeRomInfo::Favourite);
if ( s.empty() || ( s.compare("1") != 0 ))
return false;
Expand Down Expand Up @@ -944,6 +947,9 @@ int FeSettings::get_next_fav_offset() const

int FeSettings::get_next_letter_offset( int step ) const
{
if ( m_rl.empty() )
return 0;

FeRomListSorter s;

int idx = get_rom_index();
Expand Down

0 comments on commit 63c3af4

Please sign in to comment.