Skip to content

Commit

Permalink
Duke3d: fix a bunch of improperly written checks for sprites that hav…
Browse files Browse the repository at this point in the history
…e been deleted or wound up outside of playable space

Fixes terminx/eduke32#307
  • Loading branch information
TerminX committed Jun 16, 2024
1 parent 8823af7 commit e962910
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions source/duke3d/src/actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ ACTOR_STATIC void G_MoveStandables(void)
auto const pSprite = &sprite[spriteNum];
int const sectNum = pSprite->sectnum;

if (sectNum < 0)
if ((unsigned)sectNum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

#ifndef EDUKE32_STANDALONE
Expand Down Expand Up @@ -3249,7 +3249,7 @@ ACTOR_STATIC void Proj_MoveCustom(int const spriteNum)

actor[spriteNum].movflag = otherSprite;

if (pSprite->sectnum < 0)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
{
A_DeleteSprite(spriteNum);
return;
Expand Down Expand Up @@ -3436,7 +3436,7 @@ ACTOR_STATIC void G_MoveWeapons(void)
int const nextSprite = nextspritestat[spriteNum];
auto const pSprite = &sprite[spriteNum];

if (pSprite->sectnum < 0)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

/* Custom projectiles */
Expand Down Expand Up @@ -3570,7 +3570,7 @@ ACTOR_STATIC void G_MoveWeapons(void)

actor[spriteNum].movflag = moveSprite;

if (pSprite->sectnum < 0)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if ((moveSprite & 49152) != 49152 && pSprite->picnum != FREEZEBLAST)
Expand Down Expand Up @@ -4243,7 +4243,7 @@ ACTOR_STATIC void G_MoveActors(void)

int switchPic;

if (pSprite->xrepeat == 0 || sectNum < 0 || sectNum >= MAXSECTORS)
if (pSprite->xrepeat == 0 || (unsigned)sectNum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

switchPic = pSprite->picnum;
Expand Down Expand Up @@ -4352,7 +4352,7 @@ ACTOR_STATIC void G_MoveActors(void)

actor[spriteNum].movflag = moveSprite;

if (pSprite->sectnum < 0)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if ((moveSprite & 49152) != 49152 && pSprite->picnum != FREEZEBLAST)
Expand Down Expand Up @@ -5648,7 +5648,7 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
int sectNum = pSprite->sectnum; // XXX: not const
int switchPic;

if (sectNum < 0 || pSprite->xrepeat == 0)
if ((unsigned)sectNum >= MAXSECTORS || pSprite->xrepeat == 0)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

switchPic = pSprite->picnum;
Expand Down Expand Up @@ -5888,7 +5888,7 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
if ((krand()&3) == 0)
setsprite(spriteNum, &pSprite->xyz);

if (pSprite->sectnum == -1)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

#ifdef YAX_ENABLE
Expand Down Expand Up @@ -5943,10 +5943,13 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
sectNum = pSprite->sectnum;
}

if ((unsigned)sectNum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

int32_t floorZ, ceilZ;
getzsofslope(sectNum, pSprite->x, pSprite->y, &ceilZ, &floorZ);

if (ceilZ == floorZ || sectNum < 0 || sectNum >= MAXSECTORS)
if (ceilZ == floorZ)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if (pSprite->z < floorZ-(2<<8))
Expand Down Expand Up @@ -5985,7 +5988,7 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
{
if (pData[2] == 0)
{
if (pSprite->sectnum == -1)
if ((unsigned)pSprite->sectnum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if ((sector[pSprite->sectnum].floorstat&2))
Expand Down Expand Up @@ -6102,7 +6105,7 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5

A_SetSprite(spriteNum,CLIPMASK0);

if (sectNum < 0 || (sector[sectNum].floorz + 256) < pSprite->z)
if ((unsigned)sectNum >= MAXSECTORS || (sector[sectNum].floorz + 256) < pSprite->z)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if (sector[sectNum].lotag == ST_2_UNDERWATER)
Expand Down Expand Up @@ -6144,7 +6147,7 @@ ACTOR_STATIC void G_MoveMisc(void) // STATNUM 5
A_Fall(spriteNum);

if (pSprite->zvel > 4096) pSprite->zvel = 4096;
if (sectNum < 0)
if ((unsigned)sectNum >= MAXSECTORS)
DELETE_SPRITE_AND_CONTINUE(spriteNum);

if (pSprite->z == actor[spriteNum].floorz-AC_FZOFFSET(spriteNum) && pData[0] < 3)
Expand Down Expand Up @@ -6752,7 +6755,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3
auto const pPlayer = g_player[playerNum].ps;

// might happen when squished into void space
if (pPlayer->cursectnum < 0)
if ((unsigned)pPlayer->cursectnum >= MAXSECTORS)
break;

if (pSprite->sectnum == pPlayer->cursectnum
Expand Down

0 comments on commit e962910

Please sign in to comment.