Subject: bug#13743: 24.2.93; Segmentation fault when trying to [s]teal a file opened elsewhere

From: Eli Zaretskii <[email-masked]>
Date: Mon, 25 Feb 2013 18:37:50 +0200

> From: Stefan Monnier <[email-masked]>
> Cc: Eli Zaretskii <[email-masked]>,  [email-masked]
> Date: Mon, 25 Feb 2013 10:25:15 -0500
> 
> >> The manifestation of the problem will be that modify_region will be
> >> called in this case, although we don't actually modify anything.  You
> >> will probably see the "modified" indicator on the mode line, something
> >> that shouldn't have happened.
> > That is indeed what happens.
> > OTOH, the existing behavior in this area is rather messy anyway:
> 
> Not only that, but it's not clear why "that shouldn't have happened".

Because we announce that the buffer was changed when in fact it
wasn't.  That's a lie.  (It also causes redisplay to work harder as a
side effect.)

> It's good to optimize away the whole add-text-properties when it ends up
> doing nothing, but it's just an optimization.

Well, avoiding lies is always an optimization, isn't it?  Life can
(and does) go on even without that optimization.

But seriously, how can you claim this not to be a bug?  Here, try this
simplified recipe:

 emacs -Q
 C-x b foo RET
 M-: (insert-char ?a 60) RET
 M-: (add-text-properties 2 10 '(face error)) RET => t

The buffer is marked modified.

 M-~

The buffer is marked unmodified.

 M-: (add-text-properties 2 10 '(face error)) RET => nil

The buffer is marked modified again, although nothing's changed, and
the value returned is nil.

You can repeat the last 2 steps forever, the buffer always becomes
modified.  I don't see how this could be anything but a bug.  Not a
catastrophe, I agree, but a bug nonetheless.

> And I don't think it's an important one here, since (as Dmitry points
> out) the likely most common case (of having `start' be right at the
> beginning of an interval object) didn't work anyway

It does work now.  More importantly, it fixed the original crash.

> and furthermore most calls to add-text-properties are likely to be
> protected by inhibit-modification-hooks.

I don't think inhibit-modification-hooks stops the file-locking prompt
from being shown, does it?