Guard against nullptr dereference (#278)

Encountered a situation where a pSoldier between bFirstID and bLastID was null and then we'd dereference it.
This commit is contained in:
Asdow
2024-02-10 17:18:19 +02:00
committed by GitHub
parent 32cae66229
commit 28a4db0355
+10 -6
View File
@@ -460,7 +460,7 @@ void AutoBandage( BOOLEAN fStart )
for ( pSoldier = MercPtrs[cnt]; cnt <= gTacticalStatus.Team[OUR_TEAM].bLastID; ++cnt, ++pSoldier ) for ( pSoldier = MercPtrs[cnt]; cnt <= gTacticalStatus.Team[OUR_TEAM].bLastID; ++cnt, ++pSoldier )
{ {
// 0verhaul: Make sure the merc is also in the sector before making him stand up! // 0verhaul: Make sure the merc is also in the sector before making him stand up!
if ( pSoldier->bActive && pSoldier->bInSector ) if (pSoldier && pSoldier->bActive && pSoldier->bInSector)
{ {
ActionDone( pSoldier ); ActionDone( pSoldier );
if ( pSoldier->bSlotItemTakenFrom != NO_SLOT ) if ( pSoldier->bSlotItemTakenFrom != NO_SLOT )
@@ -483,12 +483,16 @@ void AutoBandage( BOOLEAN fStart )
ubLoop = gTacticalStatus.Team[ gbPlayerNum ].bFirstID; ubLoop = gTacticalStatus.Team[ gbPlayerNum ].bFirstID;
for ( ; ubLoop <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++ubLoop) for ( ; ubLoop <= gTacticalStatus.Team[ gbPlayerNum ].bLastID; ++ubLoop)
{ {
ActionDone( MercPtrs[ ubLoop ] ); pSoldier = MercPtrs[ubLoop];
if (pSoldier && pSoldier->bActive && pSoldier->bInSector)
// If anyone is still doing aid animation, stop!
if ( MercPtrs[ ubLoop ]->usAnimState == GIVING_AID || MercPtrs[ ubLoop ]->usAnimState == GIVING_AID_PRN )
{ {
MercPtrs[ ubLoop ]->SoldierGotoStationaryStance( ); ActionDone(pSoldier);
// If anyone is still doing aid animation, stop!
if (pSoldier->usAnimState == GIVING_AID || pSoldier->usAnimState == GIVING_AID_PRN)
{
pSoldier->SoldierGotoStationaryStance();
}
} }
} }