Skip to content

Commit

Permalink
Don't crash if construction droids are doing construction without bei…
Browse files Browse the repository at this point in the history
…ng ordered to.

Fixes ticket:4416 and ticket:4417.

 ==23151==ERROR: AddressSanitizer: SEGV on unknown address 0x0000000000a0 (pc 0x0000006d0c0c bp 0x7ffd1869e620 sp 0x7ffd1869e600 T0)

    #0 0x6d0c0b in intBuildStarted(DROID*) /home/tmurphy/space/build/warzone2100/src/hci.cpp:2602
    #1 0x56fe33 in actionUpdateDroid(DROID*) /home/tmurphy/space/build/warzone2100/src/action.cpp:1478
  • Loading branch information
Cyp committed Jun 6, 2016
1 parent d53404f commit 4c6d778
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions src/hci.cpp
Expand Up @@ -2549,17 +2549,13 @@ static void intObjectDied(UDWORD objID)
/* Tell the interface a construction droid has finished building */
void intBuildFinished(DROID *psDroid)
{
UDWORD droidID;
DROID *psCurr;

ASSERT_OR_RETURN(, psDroid != NULL, "Invalid droid pointer");

if ((intMode == INT_OBJECT || intMode == INT_STAT) &&
objMode == IOBJ_BUILD)
if ((intMode == INT_OBJECT || intMode == INT_STAT) && objMode == IOBJ_BUILD)
{
/* Find which button the droid is on and clear it's stats */
droidID = 0;
for (psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
// Find which button the droid is on and clear its stats
unsigned droidID = 0;
for (DROID *psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
{
if (objSelectFunc((BASE_OBJECT *)psCurr))
{
Expand All @@ -2577,23 +2573,20 @@ void intBuildFinished(DROID *psDroid)
/* Tell the interface a construction droid has started building*/
void intBuildStarted(DROID *psDroid)
{
UDWORD droidID;
DROID *psCurr;

ASSERT_OR_RETURN(, psDroid != NULL, "Invalid droid pointer");

if ((intMode == INT_OBJECT || intMode == INT_STAT) &&
objMode == IOBJ_BUILD)
if ((intMode == INT_OBJECT || intMode == INT_STAT) && objMode == IOBJ_BUILD)
{
/* Find which button the droid is on and clear it's stats */
droidID = 0;
for (psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
// Find which button the droid is on and clear its stats
unsigned droidID = 0;
for (DROID *psCurr = apsDroidLists[selectedPlayer]; psCurr; psCurr = psCurr->psNext)
{
if (objSelectFunc((BASE_OBJECT *)psCurr))
if (objSelectFunc(psCurr))
{
if (psCurr == psDroid)
{
intSetStats(droidID + IDOBJ_STATSTART, ((STRUCTURE *)psCurr->order.psObj)->pStructureType);
STRUCTURE *target = castStructure(psCurr->order.psObj);
intSetStats(droidID + IDOBJ_STATSTART, target != nullptr? target->pStructureType : nullptr);
break;
}
droidID++;
Expand Down

0 comments on commit 4c6d778

Please sign in to comment.