From: storm@cua.dk (Kim F. Storm)
To: David Kastrup <dak@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Subtle bugs in interval code.
Date: Fri, 23 Mar 2007 15:03:14 +0100 [thread overview]
Message-ID: <m37it8hxb1.fsf@kfs-l.imdomain.dk> (raw)
In-Reply-To: <85d5302mzg.fsf@lola.goethe.zz> (David Kastrup's message of "Fri\, 23 Mar 2007 12\:55\:15 +0100")
David Kastrup <dak@gnu.org> 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 <storm@cua.dk> http://www.cua.dk
next prev parent reply other threads:[~2007-03-23 14:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-23 11:45 Subtle bugs in interval code Kim F. Storm
2007-03-23 11:55 ` David Kastrup
2007-03-23 14:03 ` Kim F. Storm [this message]
2007-03-23 14:59 ` Johan Bockgård
2007-03-23 15:42 ` Kim F. Storm
2007-03-23 22:32 ` Richard Stallman
2007-03-25 1:19 ` Kim F. Storm
2007-03-25 17:27 ` Richard Stallman
2007-03-25 22:47 ` Kim F. Storm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m37it8hxb1.fsf@kfs-l.imdomain.dk \
--to=storm@cua.dk \
--cc=dak@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.