diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index e8b1925eb..604e4aa62 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -5586,7 +5586,16 @@ static void drawsprite_classic(int32_t snum) int32_t tilenum; int32_t cstat = tspr->cstat; - if ((unsigned)tspr->picnum >= MAXTILES || sec==NULL) + if (sec == NULL) + return; + + if (bad_tspr(tspr)) + return; + + // This happens when using steroids. + // XXX: Should we instead run the code but handle stuff indexed by + // tspr->owner specially? + if ((unsigned)tspr->owner >= MAXSPRITES) return; DO_TILE_ANIM(tspr->picnum, spritenum+32768); diff --git a/polymer/eduke32/build/src/engine_priv.h b/polymer/eduke32/build/src/engine_priv.h index fd0b205f4..f8d9707fc 100644 --- a/polymer/eduke32/build/src/engine_priv.h +++ b/polymer/eduke32/build/src/engine_priv.h @@ -93,6 +93,11 @@ void set_globalang(int16_t ang); if (picanm[Picnum].sf&PICANM_ANIMTYPE_MASK) Picnum += animateoffs(Picnum, Fakevar); \ } while (0) +static inline int32_t bad_tspr(const spritetype *tspr) +{ + return ((unsigned)tspr->owner >= MAXSPRITES || (unsigned)tspr->picnum >= MAXTILES); +} + void dorotspr_handle_bit2(int32_t *sx, int32_t *sy, int32_t *z, int32_t dastat, int32_t cx1_plus_cx2, int32_t cy1_plus_cy2, int32_t *ret_ouryxaspect, int32_t *ret_ourxyaspect); diff --git a/polymer/eduke32/build/src/polymer.c b/polymer/eduke32/build/src/polymer.c index 6efdc19e2..9570f940b 100644 --- a/polymer/eduke32/build/src/polymer.c +++ b/polymer/eduke32/build/src/polymer.c @@ -1342,7 +1342,8 @@ void polymer_drawsprite(int32_t snum) tspr = tspriteptr[snum]; - if (tspr->owner < 0 || tspr->picnum < 0) return; + if (bad_tspr(tspr)) + return; if ((tspr->cstat & 8192) && (depth && !mirrors[depth-1].plane)) return; diff --git a/polymer/eduke32/build/src/polymost.c b/polymer/eduke32/build/src/polymost.c index 4430ee0d5..4b8749f04 100644 --- a/polymer/eduke32/build/src/polymost.c +++ b/polymer/eduke32/build/src/polymost.c @@ -4875,7 +4875,8 @@ void polymost_drawsprite(int32_t snum) int32_t tsizx, tsizy; tspr = tspriteptr[snum]; - if (tspr->owner < 0 || tspr->picnum < 0 || tspr->picnum >= MAXTILES) return; + if (bad_tspr(tspr)) + return; spritenum = tspr->owner; diff --git a/polymer/eduke32/source/macros.h b/polymer/eduke32/source/macros.h index 63ad9d14b..041298812 100644 --- a/polymer/eduke32/source/macros.h +++ b/polymer/eduke32/source/macros.h @@ -43,7 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // mask definitions -#define BIT(shift) (1<<(shift)) +#define BIT(shift) (1u<<(shift)) #define TEST_SYNC_KEY(bits, sync_num) TEST(bits, BIT(sync_num)) diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 82f6e06ae..8286d1970 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -2492,7 +2492,7 @@ void P_HandleSharedKeys(int32_t snum) } } - j = sb_snum & ((15<interface_toggle_flag;