bsputils: add leafnum bounds check to Light_PointInSolid_r

This commit is contained in:
Eric Wasylishen 2017-10-19 13:41:14 -07:00
parent 32a5a56c8f
commit 37e2b94d3e
1 changed files with 6 additions and 1 deletions

View File

@ -220,7 +220,12 @@ vec_t Plane_Dist(const vec3_t point, const dplane_t *plane)
static bool Light_PointInSolid_r(const mbsp_t *bsp, int nodenum, const vec3_t point ) static bool Light_PointInSolid_r(const mbsp_t *bsp, int nodenum, const vec3_t point )
{ {
if (nodenum < 0) { if (nodenum < 0) {
mleaf_t *leaf = bsp->dleafs + (-1 - nodenum); // FIXME: Factor out into bounds-checked getter
int leafnum = (-1 - nodenum);
if (leafnum < 0 || leafnum >= bsp->numleafs) {
Error("Corrupt BSP: leaf %d is out of bounds (bsp->numleafs = %d)", leafnum, bsp->numleafs);
}
mleaf_t *leaf = &bsp->dleafs[leafnum];
return leaf->contents == CONTENTS_SOLID return leaf->contents == CONTENTS_SOLID
|| leaf->contents == CONTENTS_SKY; || leaf->contents == CONTENTS_SKY;