[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 644f77b: Avoid assertion violations when using mark
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] master 644f77b: Avoid assertion violations when using marker positions |
Date: |
Tue, 6 Sep 2016 16:47:34 +0000 (UTC) |
branch: master
commit 644f77b517180c5f75a9eaac4d76b12a1f334ce6
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
Avoid assertion violations when using marker positions
* src/intervals.c (set_point_from_marker): If MARKER comes from
another buffer, recalculate its byte position before using it to
set point.
* src/marker.c (set_marker_internal): If POSITION is a marker from
another buffer, recalculate its byte position before using it.
(Bug#24368)
---
src/intervals.c | 13 +++++++++----
src/marker.c | 6 +++++-
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/intervals.c b/src/intervals.c
index 8451069..e797e25 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -1821,11 +1821,16 @@ set_point (ptrdiff_t charpos)
void
set_point_from_marker (Lisp_Object marker)
{
+ ptrdiff_t charpos = clip_to_bounds (BEGV, marker_position (marker), ZV);
+ ptrdiff_t bytepos = marker_byte_position (marker);
+
+ /* Don't trust the byte position if the marker belongs to a
+ different buffer. */
if (XMARKER (marker)->buffer != current_buffer)
- signal_error ("Marker points into wrong buffer", marker);
- set_point_both
- (clip_to_bounds (BEGV, marker_position (marker), ZV),
- clip_to_bounds (BEGV_BYTE, marker_byte_position (marker), ZV_BYTE));
+ bytepos = buf_charpos_to_bytepos (current_buffer, charpos);
+ else
+ bytepos = clip_to_bounds (BEGV_BYTE, bytepos, ZV_BYTE);
+ set_point_both (charpos, bytepos);
}
/* If there's an invisible character at position POS + TEST_OFFS in the
diff --git a/src/marker.c b/src/marker.c
index febdb17..05e5bb8 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -507,7 +507,11 @@ set_marker_internal (Lisp_Object marker, Lisp_Object
position,
charpos = clip_to_bounds
(restricted ? BUF_BEGV (b) : BUF_BEG (b), charpos,
restricted ? BUF_ZV (b) : BUF_Z (b));
- if (bytepos == -1)
+ /* Don't believe BYTEPOS if it comes from a different buffer,
+ since that buffer might have a very different correspondence
+ between character and byte positions. */
+ if (bytepos == -1
+ || !(MARKERP (position) && XMARKER (position)->buffer == b))
bytepos = buf_charpos_to_bytepos (b, charpos);
else
bytepos = clip_to_bounds
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 644f77b: Avoid assertion violations when using marker positions,
Eli Zaretskii <=