From fba778d9c00e79857ded62e5850712f5746fabff Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 25 Dec 2007 18:02:44 +0000 Subject: [PATCH] fix "warping" bug MrBougo found in the protocol (namely, values near +4096 causing an integer overflow when errorneously sent as 13.3bit fixed points) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7866 d7cf8633-e32d-0410-b094-e92efae38249 --- protocol.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/protocol.c b/protocol.c index 1be46fbb..8413c658 100644 --- a/protocol.c +++ b/protocol.c @@ -1805,8 +1805,17 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi else { bits = changedbits; - if ((bits & E5_ORIGIN) && ((s->flags & RENDER_EXTERIORMODEL) || s->origin[0] < -4096 || s->origin[0] >= 4096 || s->origin[1] < -4096 || s->origin[1] >= 4096 || s->origin[2] < -4096 || s->origin[2] >= 4096)) + if ((bits & E5_ORIGIN) && ((s->flags & RENDER_EXTERIORMODEL) || s->origin[0] <= -4096.0625 || s->origin[0] >= 4095.9375 || s->origin[1] <= -4096.0625 || s->origin[1] >= 4095.9375 || s->origin[2] <= -4096.0625 || s->origin[2] >= 4095.9375)) bits |= E5_ORIGIN32; + // possible values: + // negative origin: + // (int)(f * 8 - 0.5) >= -32768 + // (f * 8 - 0.5) > -32769 + // f > -4096.0625 + // positive origin: + // (int)(f * 8 + 0.5) <= 32767 + // (f * 8 + 0.5) < 32768 + // f * 8 + 0.5) < 4095.9375 if ((bits & E5_ANGLES) && !(s->flags & RENDER_LOWPRECISION)) bits |= E5_ANGLES16; if ((bits & E5_MODEL) && s->modelindex >= 256) -- 2.39.2