Module: Mesa Branch: main Commit: 1afd0878e98aedeadd4f27186e5080bb33f55f67 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1afd0878e98aedeadd4f27186e5080bb33f55f67
Author: Rhys Perry <[email protected]> Date: Wed Sep 27 14:23:09 2023 +0100 nir/lower_shader_calls: skip zero-sized qsort Fixes UBSan: src/compiler/nir/nir_lower_shader_calls.c:1681:7: runtime error: null pointer passed as argument 1, which is declared to never be null Signed-off-by: Rhys Perry <[email protected]> Reviewed-by: Timur Kristóf <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25853> --- src/compiler/nir/nir_lower_shader_calls.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_lower_shader_calls.c b/src/compiler/nir/nir_lower_shader_calls.c index c10f9301d64..d9e2a33966c 100644 --- a/src/compiler/nir/nir_lower_shader_calls.c +++ b/src/compiler/nir/nir_lower_shader_calls.c @@ -1678,10 +1678,12 @@ nir_opt_sort_and_pack_stack(nir_shader *shader, } /* Sort scratch item by component size. */ - qsort(util_dynarray_begin(&ops), - util_dynarray_num_elements(&ops, struct scratch_item), - sizeof(struct scratch_item), - sort_scratch_item_by_size_and_value_id); + if (util_dynarray_num_elements(&ops, struct scratch_item)) { + qsort(util_dynarray_begin(&ops), + util_dynarray_num_elements(&ops, struct scratch_item), + sizeof(struct scratch_item), + sort_scratch_item_by_size_and_value_id); + } /* Reorder things on the stack */ _mesa_hash_table_u64_clear(value_id_to_item);
