mesa: don't smash the stack in _mesa_find_used_registers
authorLuca Barbieri <luca@luca-barbieri.com>
Sun, 5 Sep 2010 15:57:12 +0000 (17:57 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Sun, 5 Sep 2010 15:57:12 +0000 (17:57 +0200)
At some point this actually triggered, not sure if it still does.

Give a meaningful assert and refuse to smash the stack anyway.

src/mesa/program/program.c

index 3b6d68274465bbe7bd0e646836487feddf29ae25..06b9539bda63be4d76626e9422a58c8a3bd956b1 100644 (file)
@@ -876,12 +876,16 @@ _mesa_find_used_registers(const struct gl_program *prog,
       const GLuint n = _mesa_num_inst_src_regs(inst->Opcode);
 
       if (inst->DstReg.File == file) {
-         used[inst->DstReg.Index] = GL_TRUE;
+         ASSERT(inst->DstReg.Index < usedSize);
+         if(inst->DstReg.Index < usedSize)
+            used[inst->DstReg.Index] = GL_TRUE;
       }
 
       for (j = 0; j < n; j++) {
          if (inst->SrcReg[j].File == file) {
-            used[inst->SrcReg[j].Index] = GL_TRUE;
+            ASSERT(inst->SrcReg[j].Index < usedSize);
+            if(inst->SrcReg[j].Index < usedSize)
+               used[inst->SrcReg[j].Index] = GL_TRUE;
          }
       }
    }