[Mesa-dev] [PATCH 03/12] list: fix list_replace() for empty lists

Jason Ekstrand jason at jlekstrand.net
Sat Jul 2 22:15:25 UTC 2016


On Jul 2, 2016 9:52 AM, "Rob Clark" <robdclark at gmail.com> wrote:
>
> Before, it would happily copy list_head next/prev (ie. pointer to the
> *from* list_head), leaving things in a confused state and causing much
> mayhem.

Heh, so it would... Thanks for fixing that.

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

> Signed-off-by: Rob Clark <robdclark at gmail.com>
> ---
>  src/util/list.h | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/src/util/list.h b/src/util/list.h
> index f0dec5d..e8a99ac 100644
> --- a/src/util/list.h
> +++ b/src/util/list.h
> @@ -71,12 +71,18 @@ static inline void list_addtail(struct list_head
*item, struct list_head *list)
>      list->prev = item;
>  }
>
> +static inline bool list_empty(struct list_head *list);
> +
>  static inline void list_replace(struct list_head *from, struct list_head
*to)
>  {
> -    to->prev = from->prev;
> -    to->next = from->next;
> -    from->next->prev = to;
> -    from->prev->next = to;
> +    if (list_empty(from)) {
> +        list_inithead(to);
> +    } else {
> +        to->prev = from->prev;
> +        to->next = from->next;
> +        from->next->prev = to;
> +        from->prev->next = to;
> +    }
>  }
>
>  static inline void list_del(struct list_head *item)
> --
> 2.7.4
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160702/64befa20/attachment.html>


More information about the mesa-dev mailing list