diff options
| author | Demi Marie Obenour <demi@invisiblethingslab.com> | 2024-08-05 12:49:49 -0400 |
|---|---|---|
| committer | Demi Marie Obenour <demi@invisiblethingslab.com> | 2024-11-30 11:31:36 -0500 |
| commit | 290c36bc507d7d2f391b7eb1dc8fd9841c37e770 (patch) | |
| tree | 86e61cf7610fb2956352e9bbf719954cd742292f /tests | |
| parent | connection: Avoid undefined pointer arithmetic (diff) | |
| download | wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar.gz wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar.bz2 wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar.lz wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar.xz wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.tar.zst wayland-290c36bc507d7d2f391b7eb1dc8fd9841c37e770.zip | |
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>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/display-test.c | 18 | ||||
| -rw-r--r-- | tests/test-compositor.c | 2 | ||||
| -rw-r--r-- | tests/test-compositor.h | 14 |
3 files changed, 23 insertions, 11 deletions
diff --git a/tests/display-test.c b/tests/display-test.c index c2def44..89606c7 100644 --- a/tests/display-test.c +++ b/tests/display-test.c @@ -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, ®istry_listener_filtered, data); + wl_registry_add_listener(registry, ®istry_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; diff --git a/tests/test-compositor.c b/tests/test-compositor.c index 8648fb6..8ec0631 100644 --- a/tests/test-compositor.c +++ b/tests/test-compositor.c @@ -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); diff --git a/tests/test-compositor.h b/tests/test-compositor.h index 3fb390c..662a81c 100644 --- a/tests/test-compositor.h +++ b/tests/test-compositor.h @@ -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)) |
