From 046b1da8a8f46cc28669836505eaf2ee35d9a076 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 17 Nov 2024 13:05:15 +0300 Subject: [PATCH] ref: fix some possible off by one errors --- ref/gl/gl_rpart.c | 2 +- ref/gl/gl_triapi.c | 2 +- ref/soft/r_part.c | 2 +- ref/soft/r_rast.c | 4 ++-- ref/soft/r_triapi.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ref/gl/gl_rpart.c b/ref/gl/gl_rpart.c index 963f7323..9264170d 100644 --- a/ref/gl/gl_rpart.c +++ b/ref/gl/gl_rpart.c @@ -229,7 +229,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) VectorAdd( verts[0], delta, verts[2] ); VectorAdd( verts[1], delta, verts[3] ); - if( p->color < 0 || p->color > sizeof( gTracerColors ) / sizeof( gTracerColors[0] )) + if( p->color < 0 || p->color >= sizeof( gTracerColors ) / sizeof( gTracerColors[0] )) { p->color = TRACER_COLORINDEX_DEFAULT; } diff --git a/ref/gl/gl_triapi.c b/ref/gl/gl_triapi.c index f36120c4..2c23c2f6 100644 --- a/ref/gl/gl_triapi.c +++ b/ref/gl/gl_triapi.c @@ -245,7 +245,7 @@ int TriSpriteTexture( model_t *pSpriteModel, int frame ) if(( gl_texturenum = R_GetSpriteTexture( pSpriteModel, frame )) == 0 ) return 0; - if( gl_texturenum <= 0 || gl_texturenum > MAX_TEXTURES ) + if( gl_texturenum <= 0 || gl_texturenum >= MAX_TEXTURES ) gl_texturenum = tr.defaultTexture; GL_Bind( XASH_TEXTURE0, gl_texturenum ); diff --git a/ref/soft/r_part.c b/ref/soft/r_part.c index fef1e0c1..6424fdbd 100644 --- a/ref/soft/r_part.c +++ b/ref/soft/r_part.c @@ -240,7 +240,7 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers VectorAdd( verts[0], delta, verts[2] ); VectorAdd( verts[1], delta, verts[3] ); - if( p->color < 0 || p->color > sizeof( gTracerColors ) / sizeof( gTracerColors[0] )) + if( p->color < 0 || p->color >= sizeof( gTracerColors ) / sizeof( gTracerColors[0] )) { p->color = TRACER_COLORINDEX_DEFAULT; } diff --git a/ref/soft/r_rast.c b/ref/soft/r_rast.c index 1c316f13..339ff0d7 100644 --- a/ref/soft/r_rast.c +++ b/ref/soft/r_rast.c @@ -224,7 +224,7 @@ static void R_EmitEdge( mvertex_t *pv0, mvertex_t *pv1 ) v = ceilv0; v2 = r_ceilv1 - 1; - if( v < 0 || v > MAXHEIGHT ) + if( v < 0 || v >= MAXHEIGHT ) { gEngfuncs.Con_Printf( S_ERROR "trailing edge overflow : %d\n", v ); return; @@ -242,7 +242,7 @@ static void R_EmitEdge( mvertex_t *pv0, mvertex_t *pv1 ) v2 = ceilv0 - 1; v = r_ceilv1; - if( v < 0 || v > MAXHEIGHT ) + if( v < 0 || v >= MAXHEIGHT ) { gEngfuncs.Con_Printf( S_ERROR "leading edge overflow : %d\n", v ); return; diff --git a/ref/soft/r_triapi.c b/ref/soft/r_triapi.c index cbcdcecd..db829c77 100644 --- a/ref/soft/r_triapi.c +++ b/ref/soft/r_triapi.c @@ -289,7 +289,7 @@ int TriSpriteTexture( model_t *pSpriteModel, int frame ) if(( gl_texturenum = R_GetSpriteTexture( pSpriteModel, frame )) == 0 ) return 0; - if( gl_texturenum <= 0 || gl_texturenum > MAX_TEXTURES ) + if( gl_texturenum <= 0 || gl_texturenum >= MAX_TEXTURES ) gl_texturenum = tr.defaultTexture; GL_Bind( XASH_TEXTURE0, gl_texturenum );