tests: Avoid calling function with wrong type

Calling a function with the wrong type is immediate undefined behavior,
even if the ABI says it should be harmless.  UBSAN picks it up
immediately, and any decent control-flow integrity mechanism will as
well.

Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
This commit is contained in:
Demi Marie Obenour 2024-08-05 12:49:49 -04:00
parent 4273a5edc8
commit 290c36bc50
3 changed files with 23 additions and 11 deletions

View file

@ -924,7 +924,7 @@ TEST(versions)
}
static void
check_error_on_destroyed_object(void *data)
check_error_on_destroyed_object(void)
{
struct client *c;
struct wl_seat *seat;
@ -1043,7 +1043,7 @@ TEST(filtered_global_is_hidden)
1, d, bind_data_offer);
wl_display_set_global_filter(d->wl_display, global_filter, NULL);
client_create_noarg(d, get_globals);
client_create(d, get_globals, NULL);
display_run(d);
wl_global_destroy(g);
@ -1052,13 +1052,13 @@ TEST(filtered_global_is_hidden)
}
static void
get_dynamic_globals(void *data)
get_dynamic_globals(void)
{
struct client *c = client_connect();
struct wl_registry *registry;
registry = wl_display_get_registry(c->wl_display);
wl_registry_add_listener(registry, &registry_listener_filtered, data);
wl_registry_add_listener(registry, &registry_listener_filtered, NULL);
wl_display_roundtrip(c->wl_display);
/* Wait for the server to create a new global */
@ -1206,7 +1206,7 @@ static const struct wl_registry_listener zombie_fd_registry_listener = {
};
static void
zombie_client(void *data)
zombie_client(void)
{
struct client *c = client_connect();
struct wl_registry *registry;
@ -1376,7 +1376,7 @@ static const struct wl_registry_listener double_zombie_fd_registry_listener = {
};
static void
double_zombie_client(void *data)
double_zombie_client(void)
{
struct client *c = client_connect();
struct wl_registry *registry;
@ -1436,7 +1436,7 @@ static const struct wl_registry_listener bind_interface_mismatch_registry_listen
};
static void
registry_bind_interface_mismatch_client(void *data)
registry_bind_interface_mismatch_client(void)
{
struct client *c = client_connect();
struct wl_registry *registry;
@ -1598,7 +1598,7 @@ static const struct wl_registry_listener global_remove_before_registry_listener
};
static void
global_remove_before_client(void *data)
global_remove_before_client(void)
{
struct client *c = client_connect();
struct wl_registry *registry;
@ -1648,7 +1648,7 @@ static const struct wl_registry_listener global_remove_after_registry_listener =
};
static void
global_remove_after_client(void *data)
global_remove_after_client(void)
{
struct client *c = client_connect();
struct wl_registry *registry;

View file

@ -507,7 +507,7 @@ static const struct wl_registry_listener registry_listener =
NULL
};
struct client *client_connect()
struct client *client_connect(void)
{
struct wl_registry *reg;
struct client *c = calloc(1, sizeof *c);

View file

@ -118,5 +118,17 @@ struct client_info *client_create_with_name(struct display *d,
void *data,
const char *name);
#define client_create(d, c, data) client_create_with_name((d), (c), data, (#c))
static inline void noarg_cb(void *data)
{
void (*cb)(void) = data;
cb();
}
static inline struct client_info *client_create_with_name_noarg(struct display *d,
void (*client_main)(void),
const char *name)
{
return client_create_with_name(d, noarg_cb, client_main, name);
}
#define client_create_noarg(d, c) \
client_create_with_name((d), (void(*)(void *)) (c), NULL, (#c))
client_create_with_name_noarg((d), (c), (#c))