Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: LinkList implementation
- X-seq: zsh-workers 27760
- From: Michael Hwang <michael.a.hwang@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: LinkList implementation
- Date: Sat, 27 Feb 2010 17:45:23 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=9d5ht8u8sV3m+3fJFd43QuGruQ6FrD/qqWiRsztkbww=; b=xBPYI4WIUktBiqhq06gco2MNKFvetvh3l3/RDD+X2RQ55Ex2YGWoMjT78j5XLFvjf7 S6aK+NowEzy4mhpHoDv5plxzmisZyY7xesuCNGYaStdTzAoCp0YNqDBK69LL/J8CZHR5 21wF//9vKmn5ooLTuFe8arlwMNiNlr29RCtYg=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=IEGDmUAK2QuM3YiWLGIkR6UfMhA4yKYo+lw6WvFW/ovrlDrhJR1N5NEvsHipMsq2iI 4+3Oc+MGVHsKp+0LvjdURr6JJ0HwYxxhjvN7GwjQ2OQPUV+o+iQb3dDNwR3MeeSrYtWq mRlS1iSyUxmlJu4fLW9xCSSOMCNp+GX4J6hqw=
- In-reply-to: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@xxxxxxxxxxxxxx>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@xxxxxxxxxxxxxx>
Sorry, I made a typo. The second code snippet is from newlinklist(),
not newlinknode(), as I wrote.
Michael Hwang
On Sat, Feb 27, 2010 at 5:33 PM, Michael Hwang
<michael.a.hwang@xxxxxxxxx> wrote:
> In the process of writing a new builtin, I discovered an oddity of
> zsh's implementation of LinkList, which is a doubly linked list.
>
> LinkList alist = newlinklist();
> LinkNode node;
> for (node = lastnode(alist); node; decnode(alist)) {
> ((SomeStructPointer) getdata(node))->someField;
> }
>
> Since no nodes have been added to the LinkList, one would expect the
> body of the loop to not run at all. However, it does, and crashes
> because attempting to access someField dereferences a null pointer. I
> think this is due to this line in [z]newlinknode():
>
> list->list.last = &list->node;
>
> I'm not exactly sure why LinkLists are set up this way; I assume it's
> a tricky way to allow [z]insertlinknode() to be used in the pushnode()
> macro. However, this makes the lastnode() macro return non-null on an
> empty LinkList. Walking backwards along a LinkList is only done once
> in the entirety of zsh (the decnode() macro is only used once), which
> is why I think no one has run into this bug before. I'm hoping someone
> who has a better understanding of LinkLists can fix this.
>
> Michael Hwang
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author