Mesa (glsl2): ir_to_mesa: Provide a restricted type size to _mesa_add_uniform.

Eric Anholt anholt at kemper.freedesktop.org
Tue Jul 27 22:30:02 UTC 2010


Module: Mesa
Branch: glsl2
Commit: 9a670c2e9b7e07ba43d175f3bfb23951296794c4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9a670c2e9b7e07ba43d175f3bfb23951296794c4

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Jul 27 15:10:38 2010 -0700

ir_to_mesa: Provide a restricted type size to _mesa_add_uniform.

Fixes:
glsl-uniform-out-of-bounds.

---

 src/mesa/program/ir_to_mesa.cpp |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index bd79913..fe0c19a 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -1061,6 +1061,7 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
    ir_to_mesa_src_reg src_reg;
    variable_storage *entry = find_variable_storage(ir->var);
    unsigned int loc;
+   int len;
 
    if (!entry) {
       switch (ir->var->mode) {
@@ -1089,9 +1090,17 @@ ir_to_mesa_visitor::visit(ir_dereference_variable *ir)
 
 	 assert(ir->var->type->gl_type != 0 &&
 		ir->var->type->gl_type != GL_INVALID_ENUM);
+
+	 if (ir->var->type->is_vector() ||
+	     ir->var->type->is_scalar()) {
+	    len = ir->var->type->vector_elements;
+	 } else {
+	    len = type_size(ir->var->type) * 4;
+	 }
+
 	 loc = _mesa_add_uniform(this->prog->Parameters,
 				 ir->var->name,
-				 type_size(ir->var->type) * 4,
+				 len,
 				 ir->var->type->gl_type,
 				 NULL);
 




More information about the mesa-commit mailing list