Improve serial wraparound checking

* data_device.c (SetSelection):
* primary_selection.c (SetSelection): Handle selection serial
wraparound.
This commit is contained in:
hujianwei 2022-11-11 11:16:01 +00:00
parent c90af69ecd
commit be117ac93d
2 changed files with 8 additions and 2 deletions

View file

@ -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, "

View file

@ -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;