glsl/list: use uintptr_t for exec_node_data()'s subtraction
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 19 Feb 2020 15:09:38 +0000 (15:09 +0000)
committerMarge Bot <eric+marge@anholt.net>
Thu, 12 Mar 2020 12:09:07 +0000 (12:09 +0000)
This fixes UBSan warnings when foreach_list_typed_safe() passes NULL:
pointer index expression with base 0x000000000000 overflowed to 0xffffffffffffffa8

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4157>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4157>

src/compiler/glsl/list.h

index ed77dcfab416940db5fb77df4f33cd44ece74bd7..c80f776ae16b180cfef30d9a703e9c83718aa503 100644 (file)
@@ -281,7 +281,7 @@ inline bool exec_node::is_head_sentinel() const
  * \param field Name of the field in \c type that is the embedded \c exec_node
  */
 #define exec_node_data(type, node, field) \
-   ((type *) (((char *) node) - exec_list_offsetof(type, field, node)))
+   ((type *) (((uintptr_t) node) - exec_list_offsetof(type, field, node)))
 
 #ifdef __cplusplus
 struct exec_node;