Skip to content

Commit ecd6507

Browse files
authored
[GEN][ZH] Initialize all uninitialized variables in AIPathfind (#1043)
1 parent 3e956f1 commit ecd6507

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5645,9 +5645,9 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
56455645
ICoord2D newCellCoord;
56465646
PathfindCell *newCell;
56475647
const Int adjacent[5] = {0, 1, 2, 3, 0};
5648-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
5648+
Bool neighborFlags[8] = { 0 };
56495649

5650-
UnsignedInt newCostSoFar;
5650+
UnsignedInt newCostSoFar = 0;
56515651

56525652

56535653

@@ -6586,6 +6586,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
65866586
// "closed" list is initially empty
65876587
m_closedList = NULL;
65886588

6589+
// TheSuperHackers @fix helmutbuhler This was originally uninitialized and in the loop below.
6590+
#if RETAIL_COMPATIBLE_CRC
6591+
UnsignedInt newCostSoFar = 0;
6592+
#endif
6593+
65896594
//
65906595
// Continue search until "open" list is empty, or
65916596
// until goal is found.
@@ -6647,12 +6652,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
66476652
ICoord2D newCellCoord;
66486653
PathfindCell *newCell;
66496654
const Int adjacent[5] = {0, 1, 2, 3, 0};
6650-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
6655+
Bool neighborFlags[8] = { 0 };
66516656

66526657
// TheSuperHackers @fix Mauller 23/05/2025 Fixes uninitialized variable.
6653-
// To keep retail compatibility it needs to be uninitialized in VC6 builds.
6654-
#if defined(_MSC_VER) && _MSC_VER < 1300
6655-
UnsignedInt newCostSoFar;
6658+
#if RETAIL_COMPATIBLE_CRC
6659+
// newCostSoFar defined in outer block.
66566660
#else
66576661
UnsignedInt newCostSoFar = 0;
66586662
#endif
@@ -6717,13 +6721,24 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
67176721
}
67186722
cellCount++;
67196723

6724+
#if RETAIL_COMPATIBLE_CRC
6725+
// TheSuperHackers @fix helmutbuhler 11/06/2025 The indentation was wrong on retail here.
67206726
newCostSoFar = newCell->costSoFar( parentCell );
67216727
if (clearDiameter<pathDiameter) {
67226728
int delta = pathDiameter-clearDiameter;
67236729
newCostSoFar += 0.6f*(delta*COST_ORTHOGONAL);
67246730
}
67256731
newCell->setBlockedByAlly(false);
67266732
}
6733+
#else
6734+
}
6735+
newCostSoFar = newCell->costSoFar( parentCell );
6736+
if (clearDiameter<pathDiameter) {
6737+
int delta = pathDiameter-clearDiameter;
6738+
newCostSoFar += 0.6f*(delta*COST_ORTHOGONAL);
6739+
}
6740+
newCell->setBlockedByAlly(false);
6741+
#endif
67276742
Int costRemaining = 0;
67286743
costRemaining = newCell->costToGoal( goalCell );
67296744

@@ -7699,9 +7714,9 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
76997714
ICoord2D newCellCoord;
77007715
PathfindCell *newCell;
77017716
const Int adjacent[5] = {0, 1, 2, 3, 0};
7702-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
7717+
Bool neighborFlags[8] = { 0 };
77037718

7704-
UnsignedInt newCostSoFar;
7719+
UnsignedInt newCostSoFar = 0;
77057720

77067721
for( int i=0; i<numNeighbors; i++ )
77077722
{
@@ -7952,9 +7967,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
79527967
ICoord2D newCellCoord;
79537968
PathfindCell *newCell;
79547969
const Int adjacent[5] = {0, 1, 2, 3, 0};
7955-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
7970+
Bool neighborFlags[8] = { 0 };
79567971

7957-
UnsignedInt newCostSoFar;
7972+
UnsignedInt newCostSoFar = 0;
79587973

79597974
for( int i=0; i<numNeighbors; i++ )
79607975
{

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

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6159,9 +6159,9 @@ Int Pathfinder::examineNeighboringCells(PathfindCell *parentCell, PathfindCell *
61596159
ICoord2D newCellCoord;
61606160
PathfindCell *newCell;
61616161
const Int adjacent[5] = {0, 1, 2, 3, 0};
6162-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
6162+
Bool neighborFlags[8] = { 0 };
61636163

6164-
UnsignedInt newCostSoFar;
6164+
UnsignedInt newCostSoFar = 0;
61656165

61666166

61676167

@@ -7130,6 +7130,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71307130
// "closed" list is initially empty
71317131
m_closedList = NULL;
71327132

7133+
// TheSuperHackers @fix helmutbuhler This was originally uninitialized and in the loop below.
7134+
#if RETAIL_COMPATIBLE_CRC
7135+
UnsignedInt newCostSoFar = 0;
7136+
#endif
7137+
71337138
//
71347139
// Continue search until "open" list is empty, or
71357140
// until goal is found.
@@ -7191,12 +7196,11 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
71917196
ICoord2D newCellCoord;
71927197
PathfindCell *newCell;
71937198
const Int adjacent[5] = {0, 1, 2, 3, 0};
7194-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
7199+
Bool neighborFlags[8] = { 0 };
71957200

71967201
// TheSuperHackers @fix Mauller 23/05/2025 Fixes uninitialized variable.
7197-
// To keep retail compatibility it needs to be uninitialized in VC6 builds.
7198-
#if defined(_MSC_VER) && _MSC_VER < 1300
7199-
UnsignedInt newCostSoFar;
7202+
#if RETAIL_COMPATIBLE_CRC
7203+
// newCostSoFar defined in outer block.
72007204
#else
72017205
UnsignedInt newCostSoFar = 0;
72027206
#endif
@@ -7261,13 +7265,24 @@ Path *Pathfinder::findGroundPath( const Coord3D *from,
72617265
}
72627266
cellCount++;
72637267

7268+
#if RETAIL_COMPATIBLE_CRC
7269+
// TheSuperHackers @fix helmutbuhler 11/06/2025 The indentation was wrong on retail here.
72647270
newCostSoFar = newCell->costSoFar( parentCell );
72657271
if (clearDiameter<pathDiameter) {
72667272
int delta = pathDiameter-clearDiameter;
72677273
newCostSoFar += 0.6f*(delta*COST_ORTHOGONAL);
72687274
}
72697275
newCell->setBlockedByAlly(false);
72707276
}
7277+
#else
7278+
}
7279+
newCostSoFar = newCell->costSoFar( parentCell );
7280+
if (clearDiameter<pathDiameter) {
7281+
int delta = pathDiameter-clearDiameter;
7282+
newCostSoFar += 0.6f*(delta*COST_ORTHOGONAL);
7283+
}
7284+
newCell->setBlockedByAlly(false);
7285+
#endif
72717286
Int costRemaining = 0;
72727287
costRemaining = newCell->costToGoal( goalCell );
72737288

@@ -8319,9 +8334,9 @@ Bool Pathfinder::pathDestination( Object *obj, const LocomotorSet& locomotorSet
83198334
ICoord2D newCellCoord;
83208335
PathfindCell *newCell;
83218336
const Int adjacent[5] = {0, 1, 2, 3, 0};
8322-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
8337+
Bool neighborFlags[8] = { 0 };
83238338

8324-
UnsignedInt newCostSoFar;
8339+
UnsignedInt newCostSoFar = 0;
83258340

83268341
for( int i=0; i<numNeighbors; i++ )
83278342
{
@@ -8572,9 +8587,9 @@ Int Pathfinder::checkPathCost(Object *obj, const LocomotorSet& locomotorSet, con
85728587
ICoord2D newCellCoord;
85738588
PathfindCell *newCell;
85748589
const Int adjacent[5] = {0, 1, 2, 3, 0};
8575-
Bool neighborFlags[8] = {false, false, false, false, false, false, false};
8590+
Bool neighborFlags[8] = { 0 };
85768591

8577-
UnsignedInt newCostSoFar;
8592+
UnsignedInt newCostSoFar = 0;
85788593

85798594
for( int i=0; i<numNeighbors; i++ )
85808595
{

0 commit comments

Comments
 (0)