From 5957e0f1436a3e106141d4af3c82caaabb308293 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 26 Sep 2012 22:53:53 +0000 Subject: [PATCH] Revert "Abyss crash prevention code", but make the overflow explicit. git-svn-id: https://svn.eduke32.com/eduke32@3028 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/build/src/engine.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/polymer/eduke32/build/src/engine.c b/polymer/eduke32/build/src/engine.c index 24a5e90f9..c5bec6453 100644 --- a/polymer/eduke32/build/src/engine.c +++ b/polymer/eduke32/build/src/engine.c @@ -11667,10 +11667,14 @@ restart_grand: if ((cstat&64) != 0) if ((sv->z > intz) == ((cstat&8)==0)) continue; -#if 0 // Abyss crash prevention code ((intz-sv->z)*zx overflowing a 8-bit word) - zz=(int32_t)((intz-sv->z)*vx); +#if 1 + // Abyss crash prevention code ((intz-sv->z)*zx overflowing a 8-bit word) + // PK: the reason for the crash is not the overflowing (even if it IS a problem; + // signed overflow is undefined behavior in C), but rather the idiv trap when + // the resulting quotient doesn't fit into a *signed* 32-bit integer. + zz = (uint32_t)(intz-sv->z) * vx; intx = sv->x+scale(zz,1,vz); - zz=(int32_t)((intz-sv->z)*vy); + zz = (uint32_t)(intz-sv->z) * vy; inty = sv->y+scale(zz,1,vz); #else intx = sv->x+scale(intz-sv->z,vx,vz);