nir/lower_shader_calls: skip zero-sized qsort
authorRhys Perry <pendingchaos02@gmail.com>
Wed, 27 Sep 2023 13:23:09 +0000 (14:23 +0100)
committerMarge Bot <emma+marge@anholt.net>
Wed, 25 Oct 2023 17:27:47 +0000 (17:27 +0000)
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 <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25853>

src/compiler/nir/nir_lower_shader_calls.c

index c10f930..d9e2a33 100644 (file)
@@ -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);