mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-27 00:41:08 +02:00
Added more checks to detect illegal access in CList's class
This commit is contained in:
@ -204,7 +204,7 @@ const CGHeroInstance * PlayerLocalState::getWanderingHero(size_t index)
|
||||
{
|
||||
if(index < wanderingHeroes.size())
|
||||
return wanderingHeroes[index];
|
||||
return nullptr;
|
||||
throw std::runtime_error("No hero with index " + std::to_string(index));
|
||||
}
|
||||
|
||||
void PlayerLocalState::addWanderingHero(const CGHeroInstance * hero)
|
||||
@ -235,10 +235,10 @@ void PlayerLocalState::removeWanderingHero(const CGHeroInstance * hero)
|
||||
setSelection(ownedTowns.front());
|
||||
}
|
||||
|
||||
void PlayerLocalState::swapWanderingHero(int pos1, int pos2)
|
||||
void PlayerLocalState::swapWanderingHero(size_t pos1, size_t pos2)
|
||||
{
|
||||
assert(wanderingHeroes[pos1] && wanderingHeroes[pos2]);
|
||||
std::swap(wanderingHeroes[pos1], wanderingHeroes[pos2]);
|
||||
std::swap(wanderingHeroes.at(pos1), wanderingHeroes.at(pos2));
|
||||
|
||||
adventureInt->onHeroOrderChanged();
|
||||
}
|
||||
@ -252,7 +252,7 @@ const CGTownInstance * PlayerLocalState::getOwnedTown(size_t index)
|
||||
{
|
||||
if(index < ownedTowns.size())
|
||||
return ownedTowns[index];
|
||||
return nullptr;
|
||||
throw std::runtime_error("No town with index " + std::to_string(index));
|
||||
}
|
||||
|
||||
void PlayerLocalState::addOwnedTown(const CGTownInstance * town)
|
||||
@ -278,10 +278,10 @@ void PlayerLocalState::removeOwnedTown(const CGTownInstance * town)
|
||||
setSelection(ownedTowns.front());
|
||||
}
|
||||
|
||||
void PlayerLocalState::swapOwnedTowns(int pos1, int pos2)
|
||||
void PlayerLocalState::swapOwnedTowns(size_t pos1, size_t pos2)
|
||||
{
|
||||
assert(ownedTowns[pos1] && ownedTowns[pos2]);
|
||||
std::swap(ownedTowns[pos1], ownedTowns[pos2]);
|
||||
std::swap(ownedTowns.at(pos1), ownedTowns.at(pos2));
|
||||
|
||||
adventureInt->onTownOrderChanged();
|
||||
}
|
||||
|
Reference in New Issue
Block a user