[PATCH] Use FLT_MAX macros when bounds checking

Just in case some wierd model or other file is thrown at us where the surface
extents or similar are outside of (-9999, 9999), use the FLT_MAX macro to
ensure we catch everything. I'm yet to see this actually happen in a compiled
BSP, but I do remember being bitten in the qbsp compiler code a while back.

Signed-off-by: Tyrann <tyrann@disenchant.net>
This commit is contained in:
Tyrann 2007-08-12 09:16:05 +09:30
parent b7ed0c8072
commit 1d38ad9de0
7 changed files with 25 additions and 14 deletions

View File

@ -18,6 +18,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <float.h>
#include "quakedef.h"
#include "host.h"
#include "progs.h"
@ -192,8 +194,8 @@ SetMinMaxSize(edict_t *e, float *min, float *max, qboolean rotate)
VectorCopy(min, bounds[0]);
VectorCopy(max, bounds[1]);
rmin[0] = rmin[1] = rmin[2] = 9999;
rmax[0] = rmax[1] = rmax[2] = -9999;
rmin[0] = rmin[1] = rmin[2] = FLT_MAX;
rmax[0] = rmax[1] = rmax[2] = -FLT_MAX;
for (i = 0; i <= 1; i++) {
base[0] = bounds[i][0];

View File

@ -842,8 +842,8 @@ SV_MoveBounds(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end,
{
#if 0
// debug to test against everything
boxmins[0] = boxmins[1] = boxmins[2] = -9999;
boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
boxmins[0] = boxmins[1] = boxmins[2] = -FLT_MAX;
boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = FLT_MAX;
#else
int i;

View File

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// models are the only shared resource between a client and server running
// on the same machine.
#include <float.h>
#include "common.h"
#include "model.h"
#include "qtypes.h"
@ -621,8 +623,8 @@ CalcSurfaceExtents(msurface_t *s)
mtexinfo_t *tex;
int bmins[2], bmaxs[2];
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
mins[0] = mins[1] = FLT_MAX;
maxs[0] = maxs[1] = -FLT_MAX;
tex = s->texinfo;

View File

@ -20,6 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// d_sprite.c: software top-level rasterization driver module for drawing
// sprites
#include <float.h>
#include "quakedef.h"
#include "d_local.h"
@ -387,8 +389,8 @@ D_DrawSprite(void)
// find the top and bottom vertices, and make sure there's at least one scan to
// draw
ymin = 999999.9;
ymax = -999999.9;
ymin = FLT_MAX;
ymax = -FLT_MAX;
pverts = r_spritedesc.pverts;
for (i = 0; i < r_spritedesc.nump; i++) {

View File

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// models are the only shared resource between a client and server running
// on the same machine.
#include <float.h>
#include "console.h"
#include "crc.h"
#include "glquake.h"
@ -706,8 +708,8 @@ CalcSurfaceExtents(msurface_t *s)
mtexinfo_t *tex;
int bmins[2], bmaxs[2];
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
mins[0] = mins[1] = FLT_MAX;
maxs[0] = maxs[1] = -FLT_MAX;
tex = s->texinfo;

View File

@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// gl_warp.c -- sky and water polygons
#include <float.h>
#include "console.h"
#include "gl_model.h"
#include "glquake.h"
@ -47,8 +49,8 @@ BoundPoly(int numverts, float *verts, vec3_t mins, vec3_t maxs)
int i, j;
float *v;
mins[0] = mins[1] = mins[2] = 9999;
maxs[0] = maxs[1] = maxs[2] = -9999;
mins[0] = mins[1] = mins[2] = FLT_MAX;
maxs[0] = maxs[1] = maxs[2] = -FLT_MAX;
v = verts;
for (i = 0; i < numverts; i++)
for (j = 0; j < 3; j++, v++) {

View File

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// models are the only shared resource between a client and server running
// on the same machine.
#include <float.h>
#include <stdint.h>
#include "console.h"
@ -688,8 +689,8 @@ CalcSurfaceExtents(msurface_t *s)
mtexinfo_t *tex;
int bmins[2], bmaxs[2];
mins[0] = mins[1] = 999999;
maxs[0] = maxs[1] = -99999;
mins[0] = mins[1] = FLT_MAX;
maxs[0] = maxs[1] = -FLT_MAX;
tex = s->texinfo;