mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2024-11-21 16:46:41 -08:00
vkd3d-shader/hlsl: Introduce hlsl_calloc().
This is just a wrapper of vkd3d_calloc(), that has the advantage of checking for multiplication overflow.
This commit is contained in:
parent
ef7cf9b1ad
commit
fd38c58112
Notes:
Alexandre Julliard
2023-05-08 22:34:16 +02:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Zebediah Figura (@zfigura) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/159
@ -443,7 +443,7 @@ static bool init_deref(struct hlsl_ctx *ctx, struct hlsl_deref *deref, struct hl
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(deref->path = hlsl_alloc(ctx, sizeof(*deref->path) * deref->path_len)))
|
if (!(deref->path = hlsl_calloc(ctx, deref->path_len, sizeof(*deref->path))))
|
||||||
{
|
{
|
||||||
deref->var = NULL;
|
deref->var = NULL;
|
||||||
deref->path_len = 0;
|
deref->path_len = 0;
|
||||||
@ -882,7 +882,7 @@ struct hlsl_type *hlsl_type_clone(struct hlsl_ctx *ctx, struct hlsl_type *old,
|
|||||||
|
|
||||||
type->e.record.field_count = field_count;
|
type->e.record.field_count = field_count;
|
||||||
|
|
||||||
if (!(type->e.record.fields = hlsl_alloc(ctx, field_count * sizeof(*type->e.record.fields))))
|
if (!(type->e.record.fields = hlsl_calloc(ctx, field_count, sizeof(*type->e.record.fields))))
|
||||||
{
|
{
|
||||||
vkd3d_free((void *)type->name);
|
vkd3d_free((void *)type->name);
|
||||||
vkd3d_free(type);
|
vkd3d_free(type);
|
||||||
@ -974,7 +974,7 @@ struct hlsl_ir_var *hlsl_new_var(struct hlsl_ctx *ctx, const char *name, struct
|
|||||||
if (obj_count == 0)
|
if (obj_count == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(var->objects_usage[k] = hlsl_alloc(ctx, sizeof(*var->objects_usage[0]) * obj_count)))
|
if (!(var->objects_usage[k] = hlsl_calloc(ctx, obj_count, sizeof(*var->objects_usage[0]))))
|
||||||
{
|
{
|
||||||
for (i = 0; i < k; ++i)
|
for (i = 0; i < k; ++i)
|
||||||
vkd3d_free(var->objects_usage[i]);
|
vkd3d_free(var->objects_usage[i]);
|
||||||
|
@ -939,6 +939,15 @@ static inline void *hlsl_alloc(struct hlsl_ctx *ctx, size_t size)
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void *hlsl_calloc(struct hlsl_ctx *ctx, size_t count, size_t size)
|
||||||
|
{
|
||||||
|
void *ptr = vkd3d_calloc(count, size);
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
ctx->result = VKD3D_ERROR_OUT_OF_MEMORY;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void *hlsl_realloc(struct hlsl_ctx *ctx, void *ptr, size_t size)
|
static inline void *hlsl_realloc(struct hlsl_ctx *ctx, void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
void *ret = vkd3d_realloc(ptr, size);
|
void *ret = vkd3d_realloc(ptr, size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user