From f733bda830ad6abe232a848d051e61ff46695de9 Mon Sep 17 00:00:00 2001 From: Asdow Date: Tue, 2 Aug 2022 22:29:00 +0000 Subject: [PATCH] Fixed nullptr dereference in void CommonEnterCombatModeCode( ) & added two nullptr safety checks git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@9393 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Tactical/Handle UI.cpp | 10 +++------- Tactical/Overhead.cpp | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Tactical/Handle UI.cpp b/Tactical/Handle UI.cpp index 999824b6..bd72fab8 100644 --- a/Tactical/Handle UI.cpp +++ b/Tactical/Handle UI.cpp @@ -6106,16 +6106,12 @@ BOOLEAN HandleMultiSelectionMove( INT32 sDestGridNo ) void ResetMultiSelection( ) { - SOLDIERTYPE * pSoldier; - INT32 cnt; - // OK, loop through all guys who are 'multi-selected' and // Make them move.... - - cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; - for ( pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++cnt, pSoldier++ ) + INT32 cnt = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; + for (SOLDIERTYPE* pSoldier = MercPtrs[ cnt ]; cnt <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++cnt, pSoldier++ ) { - if ( pSoldier->bActive && pSoldier->bInSector ) + if ( pSoldier && pSoldier->bActive && pSoldier->bInSector ) { if ( pSoldier->flags.uiStatusFlags & SOLDIER_MULTI_SELECTED ) { diff --git a/Tactical/Overhead.cpp b/Tactical/Overhead.cpp index 8f3a5682..ef446769 100644 --- a/Tactical/Overhead.cpp +++ b/Tactical/Overhead.cpp @@ -6428,7 +6428,7 @@ void CommonEnterCombatModeCode( ) // Loop through all mercs and make go for ( pSoldier = Menptr, cnt = 0; cnt < TOTAL_SOLDIERS; pSoldier++, ++cnt ) { - if ( pSoldier->bActive ) + if ( pSoldier && pSoldier->bActive ) { if ( pSoldier->bInSector && pSoldier->ubBodyType != CROW ) { @@ -6440,7 +6440,7 @@ void CommonEnterCombatModeCode( ) pSoldier->EVENT_StopMerc( pSoldier->sGridNo, pSoldier->ubDirection ); // END AI actions - DebugAI(AI_MSG_INFO, MercPtrs[pSoldier->ubAutoBandagingMedic], String("CancelAIAction: enter combat mode")); + DebugAI(AI_MSG_INFO, pSoldier, String("CancelAIAction: enter combat mode")); CancelAIAction( pSoldier, TRUE ); // turn off AI controlled flag