zsh-workers
 help / color / mirror / code / Atom feed
* LinkList implementation
@ 2010-02-27 22:33 Michael Hwang
  2010-02-27 22:45 ` Michael Hwang
  2010-02-28  9:06 ` Andrey Borzenkov
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Hwang @ 2010-02-27 22:33 UTC (permalink / raw)
  To: Zsh hackers list

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2010-03-07 22:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-27 22:33 LinkList implementation Michael Hwang
2010-02-27 22:45 ` Michael Hwang
2010-02-28  9:06 ` Andrey Borzenkov
2010-03-01 18:00   ` Michael Hwang
2010-03-01 18:12     ` Peter Stephenson
2010-03-06  3:48       ` [PATCH] Added LinkList documentation to linklist.c Michael Hwang
2010-03-07 21:36         ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).