Skip to content

Commit

Permalink
Fix issue where the use of a function pointer cast can trip -fsanitiz…
Browse files Browse the repository at this point in the history
…e=undefined on recent versions of clang
  • Loading branch information
darkuranium authored and SanderMertens committed Jul 11, 2024
1 parent 06ec673 commit 0476392
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion src/addons/rules/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void flecs_rule_fini(
ecs_poly_free(rule, ecs_rule_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_rule_fini_poly(void *rule)
{
flecs_rule_fini(rule);
}

void ecs_rule_fini(
ecs_rule_t *rule)
{
Expand Down Expand Up @@ -137,7 +144,7 @@ ecs_rule_t* ecs_rule_init(
}

ecs_entity_t entity = const_desc->entity;
result->dtor = (ecs_poly_dtor_t)flecs_rule_fini;
result->dtor = flecs_rule_fini_poly;

if (entity) {
EcsPoly *poly = ecs_poly_bind(world, entity, ecs_rule_t);
Expand Down
9 changes: 8 additions & 1 deletion src/addons/system/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ void flecs_system_fini(ecs_system_t *sys) {
ecs_poly_free(sys, ecs_system_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_system_fini_poly(void *sys)
{
flecs_system_fini(sys);
}

static
void flecs_system_init_timer(
ecs_world_t *world,
Expand Down Expand Up @@ -282,7 +289,7 @@ ecs_entity_t ecs_system_init(

poly->poly = system;
system->world = world;
system->dtor = (ecs_poly_dtor_t)flecs_system_fini;
system->dtor = flecs_system_fini_poly;
system->entity = entity;

ecs_query_desc_t query_desc = desc->query;
Expand Down
9 changes: 8 additions & 1 deletion src/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,13 @@ void flecs_filter_fini(
}
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_filter_fini_poly(void *filter)
{
flecs_filter_fini(filter);
}

void ecs_filter_fini(
ecs_filter_t *filter)
{
Expand Down Expand Up @@ -1707,7 +1714,7 @@ ecs_filter_t* ecs_filter_init(

f->variable_names[0] = NULL;
f->iterable.init = flecs_filter_iter_init;
f->dtor = (ecs_poly_dtor_t)flecs_filter_fini;
f->dtor = flecs_filter_fini_poly;
f->entity = entity;
f->eval_count = 0;

Expand Down
9 changes: 8 additions & 1 deletion src/observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,13 @@ int flecs_multi_observer_init(
return -1;
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_observer_fini_poly(void *observer)
{
flecs_observer_fini(observer);
}

ecs_entity_t ecs_observer_init(
ecs_world_t *world,
const ecs_observer_desc_t *desc)
Expand All @@ -895,7 +902,7 @@ ecs_entity_t ecs_observer_init(

ecs_observer_t *observer = ecs_poly_new(ecs_observer_t);
ecs_assert(observer != NULL, ECS_INTERNAL_ERROR, NULL);
observer->dtor = (ecs_poly_dtor_t)flecs_observer_fini;
observer->dtor = flecs_observer_fini_poly;

/* Make writeable copy of filter desc so that we can set name. This will
* make debugging easier, as any error messages related to creating the
Expand Down
9 changes: 8 additions & 1 deletion src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,13 @@ void flecs_query_fini(
ecs_poly_free(query, ecs_query_t);
}

/* ecs_poly_dtor_t-compatible wrapper */
static
void flecs_query_fini_poly(void *query)
{
flecs_query_fini(query);
}

/* -- Public API -- */

ecs_query_t* ecs_query_init(
Expand Down Expand Up @@ -2098,7 +2105,7 @@ ecs_query_t* ecs_query_init(
}

result->iterable.init = flecs_query_iter_init;
result->dtor = (ecs_poly_dtor_t)flecs_query_fini;
result->dtor = flecs_query_fini_poly;
result->prev_match_count = -1;

result->ctx = desc->ctx;
Expand Down

0 comments on commit 0476392

Please sign in to comment.