From ee2541efee2eace042303197a1645013d22fcc34 Mon Sep 17 00:00:00 2001 From: Zack Middleton Date: Sun, 12 Jul 2015 18:38:33 -0500 Subject: [PATCH] Fix range checks for numBorders in CM_AddFacetBevels Found by Coverity. --- code/qcommon/cm_patch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/qcommon/cm_patch.c b/code/qcommon/cm_patch.c index 3cd7bcaf..6f46239d 100644 --- a/code/qcommon/cm_patch.c +++ b/code/qcommon/cm_patch.c @@ -876,7 +876,10 @@ void CM_AddFacetBevels( facet_t *facet ) { } if ( i == facet->numBorders ) { - if (facet->numBorders > 4 + 6 + 16) Com_Printf("ERROR: too many bevels\n"); + if ( facet->numBorders >= 4 + 6 + 16 ) { + Com_Printf( "ERROR: too many bevels\n" ); + continue; + } facet->borderPlanes[facet->numBorders] = CM_FindPlane2(plane, &flipped); facet->borderNoAdjust[facet->numBorders] = 0; facet->borderInward[facet->numBorders] = flipped; @@ -938,7 +941,10 @@ void CM_AddFacetBevels( facet_t *facet ) { } if ( i == facet->numBorders ) { - if (facet->numBorders > 4 + 6 + 16) Com_Printf("ERROR: too many bevels\n"); + if ( facet->numBorders >= 4 + 6 + 16 ) { + Com_Printf( "ERROR: too many bevels\n" ); + continue; + } facet->borderPlanes[facet->numBorders] = CM_FindPlane2(plane, &flipped); for ( k = 0 ; k < facet->numBorders ; k++ ) { @@ -976,6 +982,10 @@ void CM_AddFacetBevels( facet_t *facet ) { #ifndef BSPC //add opposite plane + if ( facet->numBorders >= 4 + 6 + 16 ) { + Com_Printf( "ERROR: too many bevels\n" ); + return; + } facet->borderPlanes[facet->numBorders] = facet->surfacePlane; facet->borderNoAdjust[facet->numBorders] = 0; facet->borderInward[facet->numBorders] = qtrue;