[PATCH libinput 1/5] util: allow list_remove() on a NULL node

Pekka Paalanen ppaalanen at gmail.com
Mon Jun 29 23:21:40 PDT 2015


On Mon, 29 Jun 2015 13:49:21 +1000
Peter Hutterer <peter.hutterer at who-t.net> wrote:

> Don't require a list_init() on a node before we can call list_remove on it, it
> clutters up the code for little benefit.
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  src/libinput-util.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/src/libinput-util.c b/src/libinput-util.c
> index 3a9c8db..f19695c 100644
> --- a/src/libinput-util.c
> +++ b/src/libinput-util.c
> @@ -59,6 +59,9 @@ list_insert(struct list *list, struct list *elm)
>  void
>  list_remove(struct list *elm)
>  {
> +	if (elm->next == NULL && elm->prev == NULL)
> +		return;
> +
>  	elm->prev->next = elm->next;
>  	elm->next->prev = elm->prev;
>  	elm->next = NULL;

Hi,

are you intentionally deviating from the list defined in libwayland? If
yes, that's ok by me and up to you.

I just want to point out, that a struct wl_list with prev and/or next
NULL in libwayland is always an "uninitialized" state, and no list
operations that might read those pointers are legal.

wl_list_remove() sets the prev and next to NULL *only* because we want
to crash if those pointer values are ever used. There is no other need
to set them to NULL, but if we didn't set them, many cases of list
corruption would not explode immediately at the site.

For libwayland's struct wl_list, comparing prev or next to NULL is always
a bug.


Thanks,
pq


More information about the wayland-devel mailing list