vkd3d-shader: Return a valid pointer when count=0 in param allocator (ubsan).
After compiling and linking with -fsanitize=undefined
the following
error pops up in many tests:
vkd3d_shader_main.c:2024:12: runtime error: member access within null pointer of type 'struct vkd3d_shader_param_node'
This happens in the scenario where shader_param_allocator_get()
gets
called with count = 0
but no allocation has been made yet, so
allocator->current
is NULL.
In this case the result of the function, given by:
params = &allocator->current->param[allocator->index * allocator->stride];
is an invalid non-NULL pointer.
We can't just return NULL on count == 0
, because NULL is interpreted
as a memory allocation failure on the callers. So we force allocation
of the next node even if count = 0
when allocator->current
is NULL.
Thanks @vitorhnn for showing me ubsan!