From d1b7c675f9509d1cbb1fbd02981467dce3aa588a Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 5 Apr 2023 11:15:46 -0400 Subject: [PATCH] [Cleanup] Validate for nullptrs in bot.cpp (#3232) * [Cleanup] Validate for nullptrs in bot.cpp # Notes - Validate for nullptrs in these spots in bot.cpp before using the variable. * Update bot.cpp --- zone/bot.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index f28ef25fc..13f51ec69 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -2413,6 +2413,10 @@ bool Bot::TrySecondaryWeaponAttacks(Mob* tar, const EQ::ItemInstance* s_item) { s_itemdata = s_item->GetItem(); } + if (!s_itemdata) { + return false; + } + bool use_fist = true; if (s_itemdata) { use_fist = false; @@ -3666,6 +3670,10 @@ void Bot::BotRemoveEquipItem(uint16 slot_id) void Bot::BotTradeAddItem(const EQ::ItemInstance* inst, uint16 slot_id, std::string* error_message, bool save_to_database) { + if (!inst) { + return; + } + if (save_to_database) { if (!database.botdb.SaveItemBySlot(this, slot_id, inst)) { *error_message = BotDatabase::fail::SaveItemBySlot(); @@ -4626,8 +4634,13 @@ return true; } void Bot::Damage(Mob *from, int64 damage, uint16 spell_id, EQ::skills::SkillType attack_skill, bool avoidable, int8 buffslot, bool iBuffTic, eSpecialAttacks special) { - if (spell_id == 0) + if (!from) { + return; + } + + if (spell_id == 0) { spell_id = SPELL_UNKNOWN; + } //handle EVENT_ATTACK. Resets after we have not been attacked for 12 seconds if (attacked_timer.Check()) {