From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1182 invoked by alias); 27 Feb 2010 22:33:44 -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: 27759 Received: (qmail 9507 invoked from network); 27 Feb 2010 22:33:31 -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.171 as permitted sender) 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= MIME-Version: 1.0 Date: Sat, 27 Feb 2010 17:33:24 -0500 Message-ID: <22a0ef081002271433u713e1923lb04c7d1bf369d3d0@mail.gmail.com> Subject: LinkList implementation From: Michael Hwang To: Zsh hackers list Content-Type: text/plain; charset=ISO-8859-1 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