diff --git a/polymer/eduke32/build/include/compat.h b/polymer/eduke32/build/include/compat.h index 3cfd5c46f..432bb0c2b 100644 --- a/polymer/eduke32/build/include/compat.h +++ b/polymer/eduke32/build/include/compat.h @@ -777,5 +777,8 @@ static inline void append_ext_UNSAFE(char *outbuf, const char *ext) extern void EDUKE32_ASSERT_NAME(__LINE__)(int STATIC_ASSERTION_FAILED[(cond)?1:-1]) #endif +#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0])) +#define ARRAY_SSIZE(Ar) (bssize_t)ARRAY_SIZE(Ar) + #endif // __compat_h__ diff --git a/polymer/eduke32/source/actors.c b/polymer/eduke32/source/actors.c index 8ebf880bd..3ac735349 100644 --- a/polymer/eduke32/source/actors.c +++ b/polymer/eduke32/source/actors.c @@ -117,7 +117,9 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3, STAT_PLAYER, STAT_FALLER, STAT_ZOMBIEACTOR, STAT_MISC }; - int16_t *const tempshort = (int16_t *)tempbuf; + // XXX: accesses to 'sectorlist' potentially unaligned + int16_t *const sectorlist = (int16_t *)tempbuf; + const int32_t maxsects = sizeof(tempbuf)/sizeof(int16_t); if (s->picnum == RPG && s->xrepeat < 11) goto SKIPWALLCHECK; @@ -127,12 +129,12 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3, int32_t sectcnt = 0; int32_t sectend = 1; - tempshort[0] = s->sectnum; + sectorlist[0] = s->sectnum; do { const walltype *wal; - const int32_t dasect = tempshort[sectcnt++]; + const int32_t dasect = sectorlist[sectcnt++]; const int32_t startwall = sector[dasect].wallptr; const int32_t endwall = startwall+sector[dasect].wallnum; int32_t w; @@ -163,11 +165,15 @@ void A_RadiusDamage(int32_t i, int32_t r, int32_t hp1, int32_t hp2, int32_t hp3, { int32_t dasect2; for (dasect2=sectend-1; dasect2>=0; dasect2--) - if (tempshort[dasect2] == nextsect) + if (sectorlist[dasect2] == nextsect) break; if (dasect2 < 0) - tempshort[sectend++] = nextsect; + { + if (sectend == maxsects) + goto SKIPWALLCHECK; // prevent oob access of 'sectorlist' + sectorlist[sectend++] = nextsect; + } } x1 = (((wal->x+wall[wal->point2].x)>>1)+s->x)>>1; @@ -189,7 +195,7 @@ SKIPWALLCHECK: q = -(16<<8) + (krand()&((32<<8)-1)); - for (stati=0; stati<7; stati++) // TODO: ARRAY_SIZE + for (stati=0; stati < ARRAY_SSIZE(statlist); stati++) { int32_t j = headspritestat[statlist[stati]]; diff --git a/polymer/eduke32/source/player.c b/polymer/eduke32/source/player.c index fff566b2b..5018ba42e 100644 --- a/polymer/eduke32/source/player.c +++ b/polymer/eduke32/source/player.c @@ -1816,8 +1816,6 @@ static void G_DrawWeaponTile(int32_t x, int32_t y, int32_t tilenum, int32_t shad } } -#define ARRAY_SIZE(Ar) (sizeof(Ar)/sizeof((Ar)[0])) - static int32_t P_DisplayKnee(int32_t gs,int32_t snum) { static const int8_t knee_y[] = {0,-8,-16,-32,-64,-84,-108,-108,-108,-72,-32,-8}; diff --git a/polymer/eduke32/source/sector.c b/polymer/eduke32/source/sector.c index 80eee226f..40c29daf2 100644 --- a/polymer/eduke32/source/sector.c +++ b/polymer/eduke32/source/sector.c @@ -1844,10 +1844,12 @@ void A_DamageWall(int32_t spr,int32_t dawallnum,const vec3_t *pos,int32_t atwith if (wal->picnum == TECHLIGHT4) wal->picnum = TECHLIGHTBUST4; - if (!wal->lotag) return; + if (wal->lotag == 0) + return; sn = wal->nextsector; - if (sn < 0) return; + if (sn < 0) + return; darkestwall = 0; wal = &wall[sector[sn].wallptr]; @@ -1856,17 +1858,15 @@ void A_DamageWall(int32_t spr,int32_t dawallnum,const vec3_t *pos,int32_t atwith darkestwall=wal->shade; j = krand()&1; - i= headspritestat[STAT_EFFECTOR]; - while (i >= 0) - { + + for (SPRITES_OF(STAT_EFFECTOR, i)) if (SHT == wall[dawallnum].lotag && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT) { T3 = j; T4 = darkestwall; T5 = 1; } - i = nextspritestat[i]; - } + break; } } @@ -1906,37 +1906,28 @@ int32_t Sect_DamageCeiling(int32_t sn) sector[sn].ceilingpicnum = TECHLIGHTBUST4; - if (!sector[sn].hitag) + if (sector[sn].hitag == 0) { - i = headspritesect[sn]; - while (i >= 0) + for (SPRITES_OF_SECT(sn, i)) { if (PN == SECTOREFFECTOR && SLT == SE_12_LIGHT_SWITCH) { - j = headspritestat[STAT_EFFECTOR]; - while (j >= 0) - { + for (SPRITES_OF(STAT_EFFECTOR, j)) if (sprite[j].hitag == SHT) actor[j].t_data[3] = 1; - j = nextspritestat[j]; - } break; } - i = nextspritesect[i]; } } - i = headspritestat[STAT_EFFECTOR]; j = krand()&1; - while (i >= 0) - { - if (SHT == (sector[sn].hitag) && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT) + + for (SPRITES_OF(STAT_EFFECTOR, i)) + if (SHT == sector[sn].hitag && SLT == SE_3_RANDOM_LIGHTS_AFTER_SHOT_OUT) { T3 = j; T5 = 1; } - i = nextspritestat[i]; - } return 1; } @@ -2413,28 +2404,21 @@ void A_DamageObject(int32_t i,int32_t sn) void G_AlignWarpElevators(void) { - int32_t j, i = headspritestat[STAT_EFFECTOR]; + int32_t i, j; - while (i >= 0) + for (SPRITES_OF(STAT_EFFECTOR, i)) { if (SLT == SE_17_WARP_ELEVATOR && SS > 16) { - j = headspritestat[STAT_EFFECTOR]; - while (j >= 0) + for (SPRITES_OF(STAT_EFFECTOR, j)) { - if ((sprite[j].lotag) == SE_17_WARP_ELEVATOR && i != j && - (SHT) == (sprite[j].hitag)) + if (i != j && sprite[j].lotag == SE_17_WARP_ELEVATOR && SHT == sprite[j].hitag) { - sector[sprite[j].sectnum].floorz = - sector[SECT].floorz; - sector[sprite[j].sectnum].ceilingz = - sector[SECT].ceilingz; + sector[sprite[j].sectnum].floorz = sector[SECT].floorz; + sector[sprite[j].sectnum].ceilingz = sector[SECT].ceilingz; } - - j = nextspritestat[j]; } } - i = nextspritestat[i]; } }