Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wl: Add safe-guards for touch and pointer events #701

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion platform/wayland/cog-platform-wl.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ pointer_on_enter(void *data,
static void
pointer_on_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct wl_surface *surface)
{
if (data == NULL || pointer == NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it's not needed to explicitly compare with NULL, which tends to be clearer:

Suggested change
if (data == NULL || pointer == NULL)
if (!data || !pointer)

return;

CogWlSeat *seat = data;

if (seat->pointer_target == NULL || seat->pointer.surface == NULL)
return;

if (pointer != seat->pointer_obj) {
g_critical("%s: Got pointer %p, expected %p.", G_STRFUNC, pointer, seat->pointer_obj);
return;
Expand All @@ -286,7 +292,14 @@ pointer_on_leave(void *data, struct wl_pointer *pointer, uint32_t serial, struct
static void
pointer_on_motion(void *data, struct wl_pointer *pointer, uint32_t time, wl_fixed_t fixed_x, wl_fixed_t fixed_y)
{
CogWlSeat *seat = data;
if (data == NULL || pointer == NULL)
return;

CogWlSeat *seat = data;

if (seat->pointer_target == NULL || seat->pointer.surface == NULL)
return;

CogWlDisplay *display = seat->display;

if (pointer != seat->pointer_obj) {
Expand Down Expand Up @@ -783,8 +796,14 @@ touch_on_down(void *data,
static void
touch_on_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time, int32_t id)
{
if (data == NULL || touch == NULL)
return;

CogWlSeat *seat = data;

if (seat->touch_target == NULL || seat->touch.surface == NULL)
return;

if (touch != seat->touch_obj) {
g_critical("%s: Got touch %p, expected %p.", G_STRFUNC, touch, seat->touch_obj);
return;
Expand Down Expand Up @@ -833,9 +852,15 @@ touch_on_up(void *data, struct wl_touch *touch, uint32_t serial, uint32_t time,
static void
touch_on_motion(void *data, struct wl_touch *touch, uint32_t time, int32_t id, wl_fixed_t x, wl_fixed_t y)
{
if (data == NULL || touch == NULL)
return;

CogWlSeat *seat = data;
CogWlDisplay *display = seat->display;

if (seat->touch_target == NULL || seat->touch.surface == NULL)
return;

if (touch != seat->touch_obj) {
g_critical("%s: Got touch %p, expected %p.", G_STRFUNC, touch, seat->touch_obj);
return;
Expand Down
Loading