Mesa (master): util: Fix foreach_list_typed_safe when exec_node is not at offset 0.

Jason Ekstrand jekstrand at kemper.freedesktop.org
Thu Mar 12 20:27:06 UTC 2015


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

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Mon Mar  9 18:36:30 2015 -0700

util: Fix foreach_list_typed_safe when exec_node is not at offset 0.

__next and __prev are pointers to the structure containing the exec_node
link, not the embedded exec_node.  NULL checks would fail unless the
embedded exec_node happened to be at offset 0 in the parent struct.

v2: Jason Ekstrand <jason.ekstrand at intel.com>:
   Use "(__node)->__field.next != NULL" to check for the end of the list
   instead of the "&__next->__field != NULL".  The former is far more
   obviously correct as it matches what the non-safe versions do.  The
   original code tried to avoid any use of __next as the client code may
   delete it during its execution.  However, since the looping condition is
   checked after the iteration clause but before the client code is
   executed, we know that __node is valid during the looping condition.

Signed-off-by: Jason Ekstrand <jason.ekstrand at intel.com>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Connor Abbott <cwabbott0 at gmail.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/list.h |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/glsl/list.h b/src/glsl/list.h
index ddb98f7..15fcd4a 100644
--- a/src/glsl/list.h
+++ b/src/glsl/list.h
@@ -684,7 +684,7 @@ inline void exec_node::insert_before(exec_list *before)
            exec_node_data(__type, (__list)->head, __field),                \
                * __next =                                                  \
            exec_node_data(__type, (__node)->__field.next, __field);        \
-        __next != NULL;                                                    \
+        (__node)->__field.next != NULL;                                    \
         __node = __next, __next =                                          \
            exec_node_data(__type, (__next)->__field.next, __field))
 
@@ -693,7 +693,7 @@ inline void exec_node::insert_before(exec_list *before)
            exec_node_data(__type, (__list)->tail_pred, __field),           \
                * __prev =                                                  \
            exec_node_data(__type, (__node)->__field.prev, __field);        \
-        __prev != NULL;                                                    \
+        (__node)->__field.prev != NULL;                                    \
         __node = __prev, __prev =                                          \
            exec_node_data(__type, (__prev)->__field.prev, __field))
 




More information about the mesa-commit mailing list