[PATCH libinput 1/5] util: allow list_remove() on a NULL node
Bill Spitzak
spitzak at gmail.com
Tue Jun 30 10:01:14 PDT 2015
On Tue, Jun 30, 2015 at 5:22 AM, Hans de Goede <hdegoede at redhat.com> wrote:
>
> + if (elm->next == NULL && elm->prev == NULL)
>> + return;
>> +
>> elm->prev->next = elm->next;
>> elm->next->prev = elm->prev;
>> elm->next = NULL;
>>
>>
> I do not think this is a good idea, most list implementations
> people are used to do not allow this and consider a double
> remove / del a bug.
>
I don't think he is trying to fix double-remove. What he is trying to fix
is "it was never added to a list in the first place".
I can see the desirability of this crashing if the caller thinks the
element really should be in a list. Maybe a better solution is to add an
inline "list_is_inserted(x)" that returns whether the element is in a list
(by checking one or both pointers). Then the caller can call this before
calling list_remove if it wants this check. I think you could even
distinguish double-remove by only clearing one of the pointers on remove,
that might help when debugging.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/wayland-devel/attachments/20150630/41e8a64a/attachment.html>
More information about the wayland-devel
mailing list