Skip to content

Commit

Permalink
Renderers: fix potential crash in FixRenderCommandList()
Browse files Browse the repository at this point in the history
  • Loading branch information
ec- committed Feb 3, 2023
1 parent 06a00f6 commit d2d1dc4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions code/renderer/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int s_extendedShader;
// dynamically allocated memory if it is valid.
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS];
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS+1]; // reserve one additional texmod for lightmap atlas correction

#define FILE_HASH_SIZE 1024
static shader_t* hashTable[FILE_HASH_SIZE];
Expand Down Expand Up @@ -2321,9 +2321,11 @@ sortedIndex.
static void FixRenderCommandList( int newShader ) {
renderCommandList_t *cmdList = &backEndData->commands;

if( cmdList ) {
if ( cmdList ) {
const void *curCmd = cmdList->cmds;

*( (int *)( cmdList->cmds + cmdList->used ) ) = RC_END_OF_LIST;

while ( 1 ) {
curCmd = PADP(curCmd, sizeof(void *));

Expand Down Expand Up @@ -2351,7 +2353,7 @@ static void FixRenderCommandList( int newShader ) {
int sortedIndex;
const drawSurfsCommand_t *ds_cmd = (const drawSurfsCommand_t *)curCmd;

for( i = 0, drawSurf = ds_cmd->drawSurfs; i < ds_cmd->numDrawSurfs; i++, drawSurf++ ) {
for ( i = 0, drawSurf = ds_cmd->drawSurfs; i < ds_cmd->numDrawSurfs; i++, drawSurf++ ) {
R_DecomposeSort( drawSurf->sort, &entityNum, &sh, &fogNum, &dlightMap );
sortedIndex = (( drawSurf->sort >> QSORT_SHADERNUM_SHIFT ) & SHADERNUM_MASK);
if ( sortedIndex >= newShader ) {
Expand Down
8 changes: 5 additions & 3 deletions code/renderervk/tr_shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int s_extendedShader;
// dynamically allocated memory if it is valid.
static shaderStage_t stages[MAX_SHADER_STAGES];
static shader_t shader;
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS+1]; // we reserved one additional texmod for lightmap atlas correction
static texModInfo_t texMods[MAX_SHADER_STAGES][TR_MAX_TEXMODS+1]; // reserve one additional texmod for lightmap atlas correction

#define FILE_HASH_SIZE 1024
static shader_t* hashTable[FILE_HASH_SIZE];
Expand Down Expand Up @@ -2422,9 +2422,11 @@ sortedIndex.
static void FixRenderCommandList( int newShader ) {
renderCommandList_t *cmdList = &backEndData->commands;

if( cmdList ) {
if ( cmdList ) {
const void *curCmd = cmdList->cmds;

*( (int *)( cmdList->cmds + cmdList->used ) ) = RC_END_OF_LIST;

while ( 1 ) {
curCmd = PADP(curCmd, sizeof(void *));

Expand Down Expand Up @@ -2452,7 +2454,7 @@ static void FixRenderCommandList( int newShader ) {
int sortedIndex;
const drawSurfsCommand_t *ds_cmd = (const drawSurfsCommand_t *)curCmd;

for( i = 0, drawSurf = ds_cmd->drawSurfs; i < ds_cmd->numDrawSurfs; i++, drawSurf++ ) {
for ( i = 0, drawSurf = ds_cmd->drawSurfs; i < ds_cmd->numDrawSurfs; i++, drawSurf++ ) {
R_DecomposeSort( drawSurf->sort, &entityNum, &sh, &fogNum, &dlightMap );
sortedIndex = (( drawSurf->sort >> QSORT_SHADERNUM_SHIFT ) & SHADERNUM_MASK);
if ( sortedIndex >= newShader ) {
Expand Down

0 comments on commit d2d1dc4

Please sign in to comment.