From 9b646e8108b0aa7b0cbe8ed194a99e069e9adc39 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Tue, 10 Mar 2026 13:57:16 +0000 Subject: [PATCH] Fix: Prevent null dereference in AI state updates --- Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp | 4 ++++ GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 5fc1785e434..20831f9c30f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -5025,6 +5025,8 @@ StateReturnType AIAttackFireWeaponState::onEnter() Object *obj = getMachineOwner(); AIUpdateInterface *ai = obj->getAI(); + if (!ai) + return STATE_FAILURE; // Passive stuff will approach but not attack, so we check here (after approach is complete) UnsignedInt adjust = ai->getMoodMatrixActionAdjustment(MM_Action_Attack); @@ -5314,6 +5316,8 @@ StateReturnType AIAttackState::onEnter() //CRCDEBUG_LOG(("AIAttackState::onEnter() - start for object %d", getMachineOwner()->getID())); Object* source = getMachineOwner(); AIUpdateInterface *ai = source->getAI(); + if (!ai) + return STATE_FAILURE; // if we are in sleep mode, we will not attack if ((ai->getMoodMatrixActionAdjustment(MM_Action_Attack) & MAA_Action_Ok) == 0) return STATE_SUCCESS; diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 520ec207f56..8be643e9478 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -5180,6 +5180,8 @@ StateReturnType AIAttackFireWeaponState::onEnter() Object *obj = getMachineOwner(); AIUpdateInterface *ai = obj->getAI(); + if (!ai) + return STATE_FAILURE; // Passive stuff will approach but not attack, so we check here (after approach is complete) UnsignedInt adjust = ai->getMoodMatrixActionAdjustment(MM_Action_Attack); @@ -5512,6 +5514,8 @@ StateReturnType AIAttackState::onEnter() //CRCDEBUG_LOG(("AIAttackState::onEnter() - start for object %d", getMachineOwner()->getID())); Object* source = getMachineOwner(); AIUpdateInterface *ai = source->getAI(); + if (!ai) + return STATE_FAILURE; // if we are in sleep mode, we will not attack if ((ai->getMoodMatrixActionAdjustment(MM_Action_Attack) & MAA_Action_Ok) == 0) return STATE_SUCCESS;