Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
LinkList implementation
- X-seq: zsh-workers 27759
- From: Michael Hwang <michael.a.hwang@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: LinkList implementation
- Date: Sat, 27 Feb 2010 17:33:24 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=V/GPkj82fpqOdCKUisJviCWAl0V00l1uhKSVLisAQug=; b=kEFAg52g2z+eCqhHjxoaqaMflgccqp9Lyc7NoApVo+1AaFsHnTieuKbgewyoRfm97X 03VYLc7Gcaa2S/von5QblOFQXSMf0c/9Htsp8hc9d0qnOBE2MbUUHpJzSupPD3PaQofh hMxKlIyNdlgq/I0dCnxSWhvI5dKnVNLU2NqTw=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=WE6xfmuhTa5YN5M0hTUnw67qhxsrKGxf+zpX6CvT3ST+Dzvzfa+Qtu4Nyt6Im/7xtR 6+Cx2HLevKm1wP+tYygc2LOpdyjvQNMEDPIta+ct34l76AlIiBbTF8vbiDcB+cU3u5cl vj62Qy4QqZ5aqkTyK2Itktg8dF2tG1sZ8t+gM=
- 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
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