This update adds null pointer checks and extra validations to the AttackAnythingAction::isUseful() method, preventing invalid accesses that could cause crashes. (#1135)

Checking bots and botAI before method calls.

Validating targets and confirming if they are still in the world (IsInWorld()).

Adding debug logs (LOG_DEBUG) to make it easier to identify issues.
This commit is contained in:
EricksOliveira
2025-03-29 06:58:57 -03:00
committed by GitHub
parent ad8c42d81b
commit 3faa3c639a

View File

@@ -31,7 +31,10 @@ bool AttackEnemyFlagCarrierAction::isUseful()
bool AttackAnythingAction::isUseful()
{
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot not allowed to be active
if (!bot || !botAI) // Prevents invalid accesses
return false;
if (!botAI->AllowActivity(GRIND_ACTIVITY)) // Bot cannot be active
return false;
if (botAI->HasStrategy("stay", BOT_STATE_NON_COMBAT))
@@ -41,19 +44,17 @@ bool AttackAnythingAction::isUseful()
return false;
Unit* target = GetTarget();
if (!target)
if (!target || !target->IsInWorld()) // Checks if the target is valid and in the world
return false;
std::string const name = std::string(target->GetName());
// Check for invalid targets: Dummy, Charge Target, Melee Target, Ranged Target
if (!name.empty() &&
(name.find("Dummy") != std::string::npos ||
name.find("Charge Target") != std::string::npos ||
name.find("Melee Target") != std::string::npos ||
name.find("Ranged Target") != std::string::npos))
{
return false; // Target is one of the disallowed types
return false;
}
return true;