Skip to content

Commit

Permalink
Fix probably-harmless off-by-one in DORDER_RUNBURN, which could trigg…
Browse files Browse the repository at this point in the history
…er asserts.

Also, add more related asserts.
  • Loading branch information
Cyp committed Jul 20, 2016
1 parent 6f48217 commit 31d9772
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/droid.cpp
Expand Up @@ -337,7 +337,6 @@ DROID::DROID(uint32_t id, unsigned player)
visible[vPlayer] = hasSharedVision(vPlayer, player) ? UINT8_MAX : 0;
}
memset(seenThisTick, 0, sizeof(seenThisTick));
died = 0;
periodicalDamageStart = 0;
periodicalDamage = 0;
sDisplay.screenX = OFF_SCREEN;
Expand Down Expand Up @@ -594,6 +593,8 @@ static void removeDroidFX(DROID *psDel, unsigned impactTime)

bool destroyDroid(DROID *psDel, unsigned impactTime)
{
ASSERT(gameTime - deltaGameTime < impactTime, "Expected %u < %u, gameTime = %u, bad impactTime", gameTime - deltaGameTime, impactTime, gameTime);

if (psDel->lastHitWeapon == WSC_LAS_SAT) // darken tile if lassat.
{
UDWORD width, breadth, mapX, mapY;
Expand Down
1 change: 1 addition & 0 deletions src/feature.cpp
Expand Up @@ -422,6 +422,7 @@ bool destroyFeature(FEATURE *psDel, unsigned impactTime)
Vector3i pos;

ASSERT_OR_RETURN(false, psDel != NULL, "Invalid feature pointer");
ASSERT(gameTime - deltaGameTime < impactTime, "Expected %u < %u, gameTime = %u, bad impactTime", gameTime - deltaGameTime, impactTime, gameTime);

/* Only add if visible and damageable*/
if (psDel->visible[selectedPlayer] && psDel->psStats->damageable)
Expand Down
12 changes: 3 additions & 9 deletions src/objmem.cpp
Expand Up @@ -185,17 +185,10 @@ void objmemUpdate(void)
were destroyed before this turn */

/* First remove the objects from the start of the list */
while (psDestroyedObj != NULL && psDestroyedObj->died <= gameTime - deltaGameTime)
while (psDestroyedObj != nullptr && psDestroyedObj->died <= gameTime - deltaGameTime)
{
psNext = psDestroyedObj->psNext;
if (!objmemDestroy(psDestroyedObj))
{
if (psDestroyedObj->type == OBJ_DROID)
{
debug(LOG_DEATH, "skipping %p (%s: id %u) this round, will try again later.", psDestroyedObj, ((DROID *)psDestroyedObj)->aName, ((DROID *)psDestroyedObj)->id);
return;
}
}
objmemDestroy(psDestroyedObj);
psDestroyedObj = psNext;
}

Expand Down Expand Up @@ -287,6 +280,7 @@ template <typename OBJECT>
static inline void destroyObject(OBJECT *list[], OBJECT *object)
{
ASSERT_OR_RETURN(, object != NULL, "Invalid pointer");
ASSERT(gameTime - deltaGameTime < gameTime || gameTime == 2, "Expected %u < %u, bad time", gameTime - deltaGameTime, gameTime);

// If the message to remove is the first one in the list then mark the next one as the first
if (list[object->player] == object)
Expand Down
4 changes: 2 additions & 2 deletions src/order.cpp
Expand Up @@ -921,7 +921,7 @@ void orderUpdateDroid(DROID *psDroid)
}
break;
case DORDER_RUNBURN:
if (psDroid->actionStarted + RUN_BURN_TIME < gameTime)
if (psDroid->actionStarted + RUN_BURN_TIME <= gameTime)
{
debug(LOG_DEATH, "orderUpdateDroid: Droid %d burned to death", psDroid->id); // why is this an order?
destroyDroid(psDroid, psDroid->actionStarted + RUN_BURN_TIME);
Expand All @@ -933,7 +933,7 @@ void orderUpdateDroid(DROID *psDroid)
// got there so stop running
psDroid->order = DroidOrder(DORDER_NONE);
}
if (psDroid->actionStarted + RUN_TIME < gameTime)
if (psDroid->actionStarted + RUN_TIME <= gameTime)
{
// been running long enough
actionDroid(psDroid, DACTION_NONE);
Expand Down
2 changes: 0 additions & 2 deletions src/projectile.cpp
Expand Up @@ -449,8 +449,6 @@ bool proj_SendProjectileAngled(WEAPON *psWeap, SIMPLE_OBJECT *psAttacker, int pl

psProj->bVisible = false;

psProj->died = 0;

// Must set ->psDest and ->expectedDamageCaused before first call to setProjectileDestination().
psProj->psDest = NULL;
psProj->expectedDamageCaused = objGuessFutureDamage(psStats, player, psTarget);
Expand Down
1 change: 1 addition & 0 deletions src/structure.cpp
Expand Up @@ -4637,6 +4637,7 @@ bool destroyStruct(STRUCTURE *psDel, unsigned impactTime)
const unsigned burnDurationOther = 10000;

CHECK_STRUCTURE(psDel);
ASSERT(gameTime - deltaGameTime < impactTime, "Expected %u < %u, gameTime = %u, bad impactTime", gameTime - deltaGameTime, impactTime, gameTime);

/* Firstly, are we dealing with a wall section */
const STRUCTURE_TYPE type = psDel->pStructureType->type;
Expand Down

0 comments on commit 31d9772

Please sign in to comment.