vkd3d-shader/hlsl: Avoid dereferencing rel_offset if it is NULL.

We are currently using &offset_node->loc when offset_node is NULL.

A NULL dereference of rel_offset can also happen if
hlsl_offset_from_deref() fails because the dereference is out of
bounds.
This commit is contained in:
Francisco Casas 2024-07-08 15:24:53 -04:00 committed by Henri Verbeet
parent 51abec8c99
commit eb2d320596
Notes: Henri Verbeet 2024-08-08 23:47:10 +02:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/936

View File

@ -5623,7 +5623,8 @@ bool hlsl_offset_from_deref(struct hlsl_ctx *ctx, const struct hlsl_deref *deref
size = deref->var->data_type->reg_size[regset]; size = deref->var->data_type->reg_size[regset];
if (*offset >= size) if (*offset >= size)
{ {
hlsl_error(ctx, &offset_node->loc, VKD3D_SHADER_ERROR_HLSL_OFFSET_OUT_OF_BOUNDS, /* FIXME: Report a more specific location for the constant deref. */
hlsl_error(ctx, &deref->var->loc, VKD3D_SHADER_ERROR_HLSL_OFFSET_OUT_OF_BOUNDS,
"Dereference is out of bounds. %u/%u", *offset, size); "Dereference is out of bounds. %u/%u", *offset, size);
return false; return false;
} }
@ -5638,6 +5639,7 @@ unsigned int hlsl_offset_from_deref_safe(struct hlsl_ctx *ctx, const struct hlsl
if (hlsl_offset_from_deref(ctx, deref, &offset)) if (hlsl_offset_from_deref(ctx, deref, &offset))
return offset; return offset;
if (deref->rel_offset.node)
hlsl_fixme(ctx, &deref->rel_offset.node->loc, "Dereference with non-constant offset of type %s.", hlsl_fixme(ctx, &deref->rel_offset.node->loc, "Dereference with non-constant offset of type %s.",
hlsl_node_type_to_string(deref->rel_offset.node->type)); hlsl_node_type_to_string(deref->rel_offset.node->type));