glsl: Fix crash due to negative array index
authorAnuj Phogat <anuj.phogat@gmail.com>
Thu, 18 Sep 2014 23:30:31 +0000 (16:30 -0700)
committerAnuj Phogat <anuj.phogat@gmail.com>
Wed, 22 Oct 2014 23:13:37 +0000 (16:13 -0700)
Currently Mesa crashes with a shader like this:

[fragmnet shader]
float[5] array;
int idx = -2;
void main()
{
   gl_FragColor = vec4(0.0, 1.0, 0.0, array[idx]);
}

Cc: <mesa-stable@lists.freedesktop.org>
Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
src/glsl/opt_array_splitting.cpp

index ebb076b223ebe1d1cfd84a535200582760ae78de..9e73f3c44bbfa1f57a7bf8f2e83a65e54bf3b2d5 100644 (file)
@@ -295,7 +295,7 @@ ir_array_splitting_visitor::split_deref(ir_dereference **deref)
    ir_constant *constant = deref_array->array_index->as_constant();
    assert(constant);
 
-   if (constant->value.i[0] < (int)entry->size) {
+   if (constant->value.i[0] >= 0 && constant->value.i[0] < (int)entry->size) {
       *deref = new(entry->mem_ctx)
         ir_dereference_variable(entry->components[constant->value.i[0]]);
    } else {