Skip to content

Commit e99984e

Browse files
fix(logic): Fix potential null pointer deferences in GameLogicDispatch (TheSuperHackers#2354)
1 parent 88d7df3 commit e99984e

6 files changed

Lines changed: 8 additions & 8 deletions

File tree

Generals/Code/GameEngine/Include/GameLogic/AI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ class AIGroup : public MemoryPoolObject, public Snapshot
945945
void computeIndividualDestination( Coord3D *dest, const Coord3D *groupDest,
946946
Object *obj, const Coord3D *center, Bool isFormation ); ///< compute destination of individual object, based on group destination
947947
Int getCount(); ///< return the number of objects in the group
948-
Bool isEmpty(); ///< returns true if the group has no members
948+
Bool isEmpty() const; ///< returns true if the group has no members
949949
void queueUpgrade( const UpgradeTemplate *upgrade ); ///< queue an upgrade
950950

951951
void add( Object *obj ); ///< add object to group

Generals/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Int AIGroup::getCount()
502502
/**
503503
* Returns true if the group has no members
504504
*/
505-
Bool AIGroup::isEmpty()
505+
Bool AIGroup::isEmpty() const
506506
{
507507
return m_memberList.empty();
508508
}

Generals/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static void doSetRallyPoint( Object *obj, const Coord3D& pos )
207207

208208
static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup)
209209
{
210-
if( currentlySelectedGroup )
210+
if( currentlySelectedGroup && !currentlySelectedGroup->isEmpty() )
211211
{
212212
const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
213213
DEBUG_ASSERTCRASH(selectedObjects.size() == 1, ("Trying to get single object from multiple selection!"));
@@ -532,7 +532,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
532532
Object *targetObject = findObjectByID( msg->getArgument( 0 )->objectID );
533533

534534
// issue command for either single object or for selected group
535-
if( currentlySelectedGroup )
535+
if( currentlySelectedGroup && targetObject )
536536
currentlySelectedGroup->groupCombatDrop( targetObject,
537537
*targetObject->getPosition(),
538538
CMD_FROM_PLAYER );

GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ class AIGroup : public MemoryPoolObject, public Snapshot
984984
void computeIndividualDestination( Coord3D *dest, const Coord3D *groupDest,
985985
Object *obj, const Coord3D *center, Bool isFormation ); ///< compute destination of individual object, based on group destination
986986
Int getCount(); ///< return the number of objects in the group
987-
Bool isEmpty(); ///< returns true if the group has no members
987+
Bool isEmpty() const; ///< returns true if the group has no members
988988
void queueUpgrade( const UpgradeTemplate *upgrade ); ///< queue an upgrade
989989

990990
void add( Object *obj ); ///< add object to group

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIGroup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ Int AIGroup::getCount()
502502
/**
503503
* Returns true if the group has no members
504504
*/
505-
Bool AIGroup::isEmpty()
505+
Bool AIGroup::isEmpty() const
506506
{
507507
return m_memberList.empty();
508508
}

GeneralsMD/Code/GameEngine/Source/GameLogic/System/GameLogicDispatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static void doSetRallyPoint( Object *obj, const Coord3D& pos )
208208

209209
static Object * getSingleObjectFromSelection(const AIGroup *currentlySelectedGroup)
210210
{
211-
if( currentlySelectedGroup )
211+
if( currentlySelectedGroup && !currentlySelectedGroup->isEmpty() )
212212
{
213213
const VecObjectID& selectedObjects = currentlySelectedGroup->getAllIDs();
214214
DEBUG_ASSERTCRASH(selectedObjects.size() == 1, ("Trying to get single object from multiple selection!"));
@@ -541,7 +541,7 @@ void GameLogic::logicMessageDispatcher( GameMessage *msg, void *userData )
541541
Object *targetObject = findObjectByID( msg->getArgument( 0 )->objectID );
542542

543543
// issue command for either single object or for selected group
544-
if( currentlySelectedGroup )
544+
if( currentlySelectedGroup && targetObject )
545545
currentlySelectedGroup->groupCombatDrop( targetObject,
546546
*targetObject->getPosition(),
547547
CMD_FROM_PLAYER );

0 commit comments

Comments
 (0)