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

From: Stefan Monnier <[email-masked]>
Date: Sat, 23 Feb 2013 11:59:18 -0500

> I can fix this particular problem with this simple patch:
[...]
> However, I'm not sure this is the right or the best way.  If it is, it
> will probably be prudent to add some protection against infinite
> recursion here.

How 'bout moving the

   if (BUFFERP (object))
     modify_region (object, start, end);

earlier in the function.  Something like the patch below.

        Stefan

=== modified file 'src/textprop.c'
--- src/textprop.c	2013-01-02 16:13:04 +0000
+++ src/textprop.c	2013-02-23 16:58:50 +0000
@@ -60,7 +60,7 @@
 static Lisp_Object Qread_only;
 Lisp_Object Qminibuffer_prompt;
 
-/* Sticky properties */
+/* Sticky properties.  */
 Lisp_Object Qfront_sticky, Qrear_nonsticky;
 
 /* If o1 is a cons whose cdr is a cons, return non-zero and set o2 to
@@ -1145,9 +1145,16 @@
   if (!i)
     return Qnil;
 
+  if (BUFFERP (object))
+    modify_region (object, start, end);
+
   s = XINT (start);
   len = XINT (end) - s;
 
+  /* Recompute `i' since modify_region may have performed indirectly
+     arbitrary modifications to the interval tree.  */
+  i = interval_of (s, object);
+
   /* No need to protect OBJECT, because we GC only if it's a buffer,
      and live buffers are always protected.  */
   GCPRO1 (properties);
@@ -1174,9 +1181,6 @@
 	}
     }
 
-  if (BUFFERP (object))
-    modify_region (object, start, end);
-
   /* We are at the beginning of interval I, with LEN chars to scan.  */
   for (;;)
     {