Skip to content

Commit 692e452

Browse files
committed
[GEN][ZH] Prevent dereferencing NULL pointer 'md' in populateRandomStartPosition() when starting a new game without a map (#993)
1 parent 2940669 commit 692e452

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,8 @@ static void populateRandomSideAndColor( GameInfo *game )
784784

785785
// ------------------------------------------------------------------------------------------------
786786
// ------------------------------------------------------------------------------------------------
787+
static const WaypointMap s_emptyWaypoints = WaypointMap();
788+
787789
static void populateRandomStartPosition( GameInfo *game )
788790
{
789791
if(!game)
@@ -804,12 +806,13 @@ static void populateRandomStartPosition( GameInfo *game )
804806
{
805807
if (i != j && (i<numPlayers && j<numPlayers))
806808
{
809+
const WaypointMap& waypoints = md ? md->m_waypoints : s_emptyWaypoints;
807810
AsciiString w1, w2;
808811
w1.format("Player_%d_Start", i+1);
809812
w2.format("Player_%d_Start", j+1);
810-
WaypointMap::const_iterator c1 = md->m_waypoints.find(w1);
811-
WaypointMap::const_iterator c2 = md->m_waypoints.find(w2);
812-
if (c1 == md->m_waypoints.end() || c2 == md->m_waypoints.end())
813+
WaypointMap::const_iterator c1 = waypoints.find(w1);
814+
WaypointMap::const_iterator c2 = waypoints.find(w2);
815+
if (c1 == waypoints.end() || c2 == waypoints.end())
813816
{
814817
// couldn't find a waypoint. must be kinda far away.
815818
startSpotDistance[i][j] = 1000000.0f;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ static void populateRandomSideAndColor( GameInfo *game )
829829

830830
// ------------------------------------------------------------------------------------------------
831831
// ------------------------------------------------------------------------------------------------
832+
static const WaypointMap s_emptyWaypoints = WaypointMap();
833+
832834
static void populateRandomStartPosition( GameInfo *game )
833835
{
834836
if(!game)
@@ -849,12 +851,13 @@ static void populateRandomStartPosition( GameInfo *game )
849851
{
850852
if (i != j && (i<numPlayers && j<numPlayers))
851853
{
854+
const WaypointMap& waypoints = md ? md->m_waypoints : s_emptyWaypoints;
852855
AsciiString w1, w2;
853856
w1.format("Player_%d_Start", i+1);
854857
w2.format("Player_%d_Start", j+1);
855-
WaypointMap::const_iterator c1 = md->m_waypoints.find(w1);
856-
WaypointMap::const_iterator c2 = md->m_waypoints.find(w2);
857-
if (c1 == md->m_waypoints.end() || c2 == md->m_waypoints.end())
858+
WaypointMap::const_iterator c1 = waypoints.find(w1);
859+
WaypointMap::const_iterator c2 = waypoints.find(w2);
860+
if (c1 == waypoints.end() || c2 == waypoints.end())
858861
{
859862
// couldn't find a waypoint. must be kinda far away.
860863
startSpotDistance[i][j] = 1000000.0f;

0 commit comments

Comments
 (0)