diff --git a/data_device.c b/data_device.c index 544b937..f86a9b2 100644 --- a/data_device.c +++ b/data_device.c @@ -1005,7 +1005,11 @@ SetSelection (struct wl_client *client, struct wl_resource *resource, client, wl_resource_get_id (source_resource), serial); #endif - if (serial < last_selection_change_serial) + /* Note that both serial and last_selection_change_serial are + unsigned. Remember two's complement arithmetic. -1 is + 0xffffffff, while -4294967295 overflows twice and is + 0x00000001. */ + if (serial - last_selection_change_serial > UINT32_MAX / 2) { #ifdef DEBUG fprintf (stderr, "wl_client@%p could not set the selection, " diff --git a/primary_selection.c b/primary_selection.c index 70429c8..5177fd0 100644 --- a/primary_selection.c +++ b/primary_selection.c @@ -512,7 +512,9 @@ SetSelection (struct wl_client *client, struct wl_resource *resource, /* This device is inert, since the seat has been deleted. */ return; - if (serial < last_change_serial) + /* Note that both serial and last_change_serial are unsigned. + Remember two's complement arithmetic. */ + if (serial - last_change_serial > UINT32_MAX / 2) /* This change is out of date. Do nothing. */ return;