1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fix potential access to destroyed variable on stack

This commit is contained in:
Ivan Savenko 2024-09-22 20:32:20 +00:00
parent 0058c9ba2e
commit 76e3ca4afe

View File

@ -45,11 +45,12 @@ void DamageCache::buildObstacleDamageCache(std::shared_ptr<HypotheticBattle> hb,
continue;
std::unique_ptr<spells::BattleCast> cast = nullptr;
std::unique_ptr<spells::ObstacleCasterProxy> caster = nullptr;
if(spellObstacle->obstacleType == SpellCreatedObstacle::EObstacleType::SPELL_CREATED)
{
const auto * hero = hb->battleGetFightingHero(spellObstacle->casterSide);
auto caster = spells::ObstacleCasterProxy(hb->getSidePlayer(spellObstacle->casterSide), hero, *spellObstacle);
cast = std::make_unique<spells::BattleCast>(spells::BattleCast(hb.get(), &caster, spells::Mode::PASSIVE, obst->getTrigger().toSpell()));
caster = std::make_unique<spells::ObstacleCasterProxy>(hb->getSidePlayer(spellObstacle->casterSide), hero, *spellObstacle);
cast = std::make_unique<spells::BattleCast>(spells::BattleCast(hb.get(), caster.get(), spells::Mode::PASSIVE, obst->getTrigger().toSpell()));
}
auto affectedHexes = obst->getAffectedTiles();