From 1c9ea57a4e165fa77e52f001518c8de0f9c38013 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 23 Apr 2023 15:06:53 -0400 Subject: [PATCH] [Cleanup] Fix possible nullptr in quest::addloot() (#3303) # Notes - We didn't check for `owner` before calling `owner->IsNPC()`. --- zone/questmgr.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index d6c6ee399..027f40f78 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -405,11 +405,26 @@ void QuestManager::selfcast(int spell_id) { initiator->SpellFinished(spell_id, initiator, EQ::spells::CastingSlot::Item, 0, -1, spells[spell_id].resist_difficulty); } -void QuestManager::addloot(int item_id, int charges, bool equipitem, int aug1, int aug2, int aug3, int aug4, int aug5, int aug6) { +void QuestManager::addloot( + int item_id, + int charges, + bool equipitem, + int aug1, + int aug2, + int aug3, + int aug4, + int aug5, + int aug6 +) { QuestManagerCurrentQuestVars(); - if(item_id != 0){ - if(owner->IsNPC()) + if (!owner) { + return; + } + + if (item_id != 0) { + if (owner->IsNPC()) { owner->CastToNPC()->AddItem(item_id, charges, equipitem, aug1, aug2, aug3, aug4, aug5, aug6); + } } }