From 702fc8077dcf5320f0dd7042364e17a0d2f8d372 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Wed, 24 Jan 2024 13:43:35 +0200 Subject: [PATCH] Fix possible crash on invalid spell --- lib/CBonusTypeHandler.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/CBonusTypeHandler.cpp b/lib/CBonusTypeHandler.cpp index 7244c62d2..ba86a2d8e 100644 --- a/lib/CBonusTypeHandler.cpp +++ b/lib/CBonusTypeHandler.cpp @@ -76,10 +76,10 @@ std::string CBonusTypeHandler::bonusToString(const std::shared_ptr & bonu if (text.find("${val}") != std::string::npos) boost::algorithm::replace_all(text, "${val}", std::to_string(bearer->valOfBonuses(Selector::typeSubtype(bonus->type, bonus->subtype)))); - if (text.find("${subtype.creature}") != std::string::npos && bonus->subtype.as() != CreatureID::NONE) + if (text.find("${subtype.creature}") != std::string::npos && bonus->subtype.as().hasValue()) boost::algorithm::replace_all(text, "${subtype.creature}", bonus->subtype.as().toCreature()->getNamePluralTranslated()); - if (text.find("${subtype.spell}") != std::string::npos && bonus->subtype.as() != SpellID::NONE) + if (text.find("${subtype.spell}") != std::string::npos && bonus->subtype.as().hasValue()) boost::algorithm::replace_all(text, "${subtype.spell}", bonus->subtype.as().toSpell()->getNameTranslated()); return text; @@ -95,8 +95,11 @@ ImagePath CBonusTypeHandler::bonusToGraphics(const std::shared_ptr & bonu case BonusType::SPELL_IMMUNITY: { fullPath = true; - const CSpell * sp = bonus->subtype.as().toSpell(); - fileName = sp->getIconImmune(); + if (bonus->subtype.as().hasValue()) + { + const CSpell * sp = bonus->subtype.as().toSpell(); + fileName = sp->getIconImmune(); + } break; } case BonusType::SPELL_DAMAGE_REDUCTION: //Spell damage reduction for all schools