Skip to content

Commit

Permalink
Prevent segfault on bogus instruction token.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
icculus committed Apr 19, 2008
1 parent 93b606b commit bb2d853
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mojoshader.c
Expand Up @@ -3809,6 +3809,7 @@ static const Instruction instructions[] =

static int parse_instruction_token(Context *ctx)
{
int retval = NOFAIL;
const uint32 *start_tokens = ctx->tokens;
const uint32 start_tokencount = ctx->tokencount;
const uint32 token = SWAP32(*(ctx->tokens));
Expand All @@ -3817,13 +3818,13 @@ static int parse_instruction_token(Context *ctx)
const uint32 insttoks = ((token >> 24) & 0x0F);
const int coissue = (token & 0x40000000) ? 1 : 0;
const int predicated = (token & 0x10000000) ? 1 : 0;
const Instruction *instruction = &instructions[opcode];
const emit_function emitter = instruction->emitter[ctx->profileid];
int retval = NOFAIL;

if ( opcode >= (sizeof (instructions) / sizeof (instructions[0])) )
return 0; // not an instruction token, or just not handled here.

const Instruction *instruction = &instructions[opcode];
const emit_function emitter = instruction->emitter[ctx->profileid];

if ((token & 0x80000000) != 0)
return fail(ctx, "instruction token high bit must be zero."); // so says msdn.

Expand Down

0 comments on commit bb2d853

Please sign in to comment.