From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89 invoked by alias); 27 Feb 2010 22:45:41 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 27760 Received: (qmail 2746 invoked from network); 27 Feb 2010 22:45:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VERIFIED autolearn=ham version=3.2.5 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 74.125.82.43 as permitted sender) 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= MIME-Version: 1.0 In-Reply-To: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@mail.gmail.com> References: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@mail.gmail.com> Date: Sat, 27 Feb 2010 17:45:23 -0500 Message-ID: <22a0ef081002271445l7a79aaebna536c16fed4495ae@mail.gmail.com> Subject: Re: LinkList implementation From: Michael Hwang To: Zsh hackers list Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 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 =3D newlinklist(); > LinkNode node; > for (node =3D lastnode(alist); node; decnode(alist)) { > =A0 =A0 ((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 =3D &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 >