Skip to content

Commit

Permalink
Three bugfixes for bugs found Coverity scanner.
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed Jul 4, 2015
1 parent 260a88e commit 8076d0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/astar.cpp
Expand Up @@ -100,7 +100,7 @@ struct PathNode
};
struct PathExploredTile
{
PathExploredTile() : iteration(0xFFFF) {}
PathExploredTile() : iteration(0xFFFF), dx(0), dy(0), dist(0), visited(false) {}

uint16_t iteration;
int8_t dx, dy; // Offset from previous point in the route.
Expand Down
22 changes: 7 additions & 15 deletions src/display.cpp
Expand Up @@ -2694,26 +2694,18 @@ UBYTE DroidSelectionWeights[NUM_DROID_WEIGHTS] =
of multiple selections */
static SELECTION_TYPE establishSelection(UDWORD selectedPlayer)
{
DROID *psDroid, *psDominant = NULL;
UBYTE CurrWeight;
bool atLeastOne;
SELECTION_TYPE selectionClass;
DROID *psDroid = NULL;
DROID *psDominant = NULL;
UBYTE CurrWeight = UBYTE_MAX;
SELECTION_TYPE selectionClass = SC_INVALID;

atLeastOne = false;
selectionClass = SC_INVALID;
CurrWeight = UBYTE_MAX;

for (psDroid = apsDroidLists[selectedPlayer];
psDroid /*&& !atLeastOne*/; psDroid = psDroid->psNext)
for (psDroid = apsDroidLists[selectedPlayer]; psDroid; psDroid = psDroid->psNext)
{
// This works, uses the DroidSelectionWeights[] table to priorities the different
// droid types and find the dominant selection.
if (psDroid->selected)
{
ASSERT(psDroid->droidType < NUM_DROID_WEIGHTS,
"establishSelection : droidType exceeds NUM_DROID_WEIGHTS");

atLeastOne = true;
ASSERT(psDroid->droidType < NUM_DROID_WEIGHTS, "droidType exceeds NUM_DROID_WEIGHTS");
if (DroidSelectionWeights[psDroid->droidType] < CurrWeight)
{
CurrWeight = DroidSelectionWeights[psDroid->droidType];
Expand All @@ -2722,7 +2714,7 @@ static SELECTION_TYPE establishSelection(UDWORD selectedPlayer)
}
}

if (atLeastOne)
if (psDominant)
{
psDominantSelected = psDominant;
switch (psDominant->droidType)
Expand Down
2 changes: 1 addition & 1 deletion src/hci.cpp
Expand Up @@ -2404,7 +2404,7 @@ static void intProcessObject(UDWORD id)
}
}
}
else
else if (psObj)
{
if (psObjSelected)
{
Expand Down

0 comments on commit 8076d0f

Please sign in to comment.