Mesa (master): compiler/glsl: do not downcast list sentinel

Nicolai Hähnle nh at kemper.freedesktop.org
Sat May 7 21:50:57 UTC 2016


Module: Mesa
Branch: master
Commit: 945c6887ab43a98a6e042841b2fb547aaef250e2
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=945c6887ab43a98a6e042841b2fb547aaef250e2

Author: Nicolai Hähnle <nicolai.haehnle at amd.com>
Date:   Sat Apr 30 01:36:59 2016 -0500

compiler/glsl: do not downcast list sentinel

This crashes gcc's undefined behaviour sanitizer.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

---

 src/compiler/glsl/ir.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 750f617..d69ab13 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -869,7 +869,8 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
    /* Use each component from each entry in the value_list to initialize one
     * component of the constant being constructed.
     */
-   for (unsigned i = 0; i < type->components(); /* empty */) {
+   unsigned i = 0;
+   for (;;) {
       assert(value->as_constant() != NULL);
       assert(!value->is_tail_sentinel());
 
@@ -901,6 +902,8 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
 	    break;
       }
 
+      if (i >= type->components())
+	 break; /* avoid downcasting a list sentinel */
       value = (ir_constant *) value->next;
    }
 }




More information about the mesa-commit mailing list