Prevent segfault on bogus instruction token. trunk
authorRyan C. Gordon <icculus@icculus.org>
Fri, 18 Apr 2008 21:26:41 -0400
branchtrunk
changeset 143 336b3c22ba0a
parent 142 e064b4cefb4e
child 144 2483576e1281
Prevent segfault on bogus instruction token.
mojoshader.c
--- a/mojoshader.c	Fri Apr 18 21:26:19 2008 -0400
+++ b/mojoshader.c	Fri Apr 18 21:26:41 2008 -0400
@@ -3809,6 +3809,7 @@
 
 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));
@@ -3817,13 +3818,13 @@
     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.