From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: storm@cua.dk (Kim F. Storm) Newsgroups: gmane.emacs.devel Subject: Re: Subtle bugs in interval code. Date: Fri, 23 Mar 2007 15:03:14 +0100 Message-ID: References: <85d5302mzg.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1174658643 21298 80.91.229.12 (23 Mar 2007 14:04:03 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 23 Mar 2007 14:04:03 +0000 (UTC) Cc: emacs-devel@gnu.org To: David Kastrup Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 23 15:03:45 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HUkMp-0001r9-Tu for ged-emacs-devel@m.gmane.org; Fri, 23 Mar 2007 15:03:44 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HUkOj-0002cH-VC for ged-emacs-devel@m.gmane.org; Fri, 23 Mar 2007 09:05:41 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HUkOT-0002QG-K8 for emacs-devel@gnu.org; Fri, 23 Mar 2007 10:05:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HUkOR-0002Ot-Qm for emacs-devel@gnu.org; Fri, 23 Mar 2007 10:05:24 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HUkOR-0002Oo-K3 for emacs-devel@gnu.org; Fri, 23 Mar 2007 09:05:23 -0500 Original-Received: from pfepa.post.tele.dk ([195.41.46.235]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1HUkMV-0003aa-8p; Fri, 23 Mar 2007 10:03:23 -0400 Original-Received: from kfs-l.imdomain.dk.cua.dk (unknown [80.165.4.124]) by pfepa.post.tele.dk (Postfix) with SMTP id A1324FAC072; Fri, 23 Mar 2007 15:03:20 +0100 (CET) In-Reply-To: <85d5302mzg.fsf@lola.goethe.zz> (David Kastrup's message of "Fri\, 23 Mar 2007 12\:55\:15 +0100") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.96 (gnu/linux) X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:68393 Archived-At: David Kastrup writes: > storm@cua.dk (Kim F. Storm) writes: > >> Studying the code in interval.c for merge_properties and >> intervals_equal, I noticed that they use Fmemq to search >> for a given property on a plist. >> >> That's not a safe way to do that; >> >> E.g. consider a plist like this: >> >> (setq p '(a b c d)) >> >> Now, >> >> (plist-get p 'a) => b >> (plist-get p 'b) => nil >> >> whereas >> >> (memq 'a p) => (a b c d) >> (memq 'b p) => (b c d) != nil >> >> So due to the use of Fmemq, the interval code may wrongly assume that >> the plist has a `b' member with a value of `c'. >> >> I'm not aware of any specific bugs related to this. >> >> Note that we cannot just use plist-get instead of memq, as we then >> cannot differentiate between "property is on list with nil value" >> and "property is not on list". > > One could check whether the length of the rest sequence is even. Not really. Consider: (memq 'b '(a b b c)) => (b b c) > The cleanest option might be to add an optional DEFAULT argument to > plist-get, but that would require changes to all C level callers. No good! > Maybe one should add an explicit plist-get-default function that takes > the default for non-existing elements from its third argument? That might work if you can advice on a default value that will never be a valid element value of any relevant plist... A version of memq which skips every 2nd element would work always! -- Kim F. Storm http://www.cua.dk