From 2b0c778ad1d4366f33015897e732f398f1ebdf7e Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 24 Jan 2023 17:57:12 -0500 Subject: [PATCH] [Bug Fix] Fix nullptr spell in BCSpells::Load() (#2790) * [Bug Fix] Fix nullptr spell in BCSpells::Load() # Notes - Fix possible `nullptr` where we didn't check if spell was valid before using it. * Cleanup. --- zone/bot_command.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/zone/bot_command.cpp b/zone/bot_command.cpp index f812c4d6c..b1d08bd5c 100644 --- a/zone/bot_command.cpp +++ b/zone/bot_command.cpp @@ -122,10 +122,20 @@ public: } for (int spell_id = 2; spell_id < SPDAT_RECORDS; ++spell_id) { - if (spells[spell_id].player_1[0] == '\0') + if (!IsValidSpell(spell_id)) { continue; - if (spells[spell_id].target_type != ST_Target && spells[spell_id].cast_restriction != 0) // watch + } + + if (spells[spell_id].player_1[0] == '\0') { continue; + } + + if ( + spells[spell_id].target_type != ST_Target && + spells[spell_id].cast_restriction != 0 + ) { + continue; + } auto target_type = BCEnum::TT_None; switch (spells[spell_id].target_type) {