[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] The function list operation of "_evdns_nameserver_add_impl"



Dear,

This code snippet comes from libevent-2.0.13. The list operation is
the same. I think it does not have any bugs.

yrs,



/* insert this nameserver into the list of them */
	if (!base->server_head) {
		ns->next = ns->prev = ns;
		base->server_head = ns;
	} else {
		ns->next = base->server_head->next;
		ns->prev = base->server_head;
		base->server_head->next = ns;
		if (base->server_head->prev == base->server_head) {
			base->server_head->prev = ns;
		}
	}


On 12/22/11, Nick Mathewson <nickm@xxxxxxxxxxxxx> wrote:
> On Wed, Dec 21, 2011 at 7:53 AM, wang qin <scpl0000@xxxxxxxxx> wrote:
>>
>> Dear,
>>
>> I do not understand of the list operation of the
>> _evdns_nameserver_add_impl.
>>
>> How to understand this snippet?
>>
>> Best is figures and notes.
>>
>>
>>
>> Thank you very much!
>>
>>
>>        /* insert this nameserver into the list of them */
>>        if (!server_head) {
>>                ns->next = ns->prev = ns;
>>                server_head = ns;
>>        } else {
>>                ns->next = server_head->next;
>>                ns->prev = server_head;
>>                server_head->next = ns;
>>                if (server_head->prev == server_head) {
>>                        server_head->prev = ns;
>>                }
>>        }
>
> It looks like it's supposed to be a circular doubly linked list to me.
>  If the list is empty, then the new nameserver is inserted as the sole
> node, and its prev and next pointers are set to itself (to make the
> list circular).  But if the list is notempty, we insert the new
> nameserver after the current head (server_head).
>
> It looks like there's a possible bug there; I don't see anything that
> points ns->next->prev at ns.   If that's so, the best solution here is
> probably to replace the whole thing evdns_base.server_head thing with
> a CIRCLEQ or such.
>
> (FWIW, this looks like really old code; Libevent 2.0 is the version
> folks should be using. Libevent 1.4 is not under active development.)
>
> yrs,
> --
> Nick
> ***********************************************************************
> To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
> unsubscribe libevent-users    in the body.
>
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.