diff options
| author | Eli Zaretskii | 2016-09-06 19:46:06 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2016-09-06 19:46:06 +0300 |
| commit | 644f77b517180c5f75a9eaac4d76b12a1f334ce6 (patch) | |
| tree | ecdbd5a36616cbc954ccd4e3de2e2ae8e039bb0e /src | |
| parent | dcfcc595339f8bd503dedf95976b8a3633382f4f (diff) | |
| download | emacs-644f77b517180c5f75a9eaac4d76b12a1f334ce6.tar.gz emacs-644f77b517180c5f75a9eaac4d76b12a1f334ce6.zip | |
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)
Diffstat (limited to 'src')
| -rw-r--r-- | src/intervals.c | 13 | ||||
| -rw-r--r-- | src/marker.c | 6 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/intervals.c b/src/intervals.c index 8451069708c..e797e25ce9c 100644 --- a/src/intervals.c +++ b/src/intervals.c | |||
| @@ -1821,11 +1821,16 @@ set_point (ptrdiff_t charpos) | |||
| 1821 | void | 1821 | void |
| 1822 | set_point_from_marker (Lisp_Object marker) | 1822 | set_point_from_marker (Lisp_Object marker) |
| 1823 | { | 1823 | { |
| 1824 | ptrdiff_t charpos = clip_to_bounds (BEGV, marker_position (marker), ZV); | ||
| 1825 | ptrdiff_t bytepos = marker_byte_position (marker); | ||
| 1826 | |||
| 1827 | /* Don't trust the byte position if the marker belongs to a | ||
| 1828 | different buffer. */ | ||
| 1824 | if (XMARKER (marker)->buffer != current_buffer) | 1829 | if (XMARKER (marker)->buffer != current_buffer) |
| 1825 | signal_error ("Marker points into wrong buffer", marker); | 1830 | bytepos = buf_charpos_to_bytepos (current_buffer, charpos); |
| 1826 | set_point_both | 1831 | else |
| 1827 | (clip_to_bounds (BEGV, marker_position (marker), ZV), | 1832 | bytepos = clip_to_bounds (BEGV_BYTE, bytepos, ZV_BYTE); |
| 1828 | clip_to_bounds (BEGV_BYTE, marker_byte_position (marker), ZV_BYTE)); | 1833 | set_point_both (charpos, bytepos); |
| 1829 | } | 1834 | } |
| 1830 | 1835 | ||
| 1831 | /* If there's an invisible character at position POS + TEST_OFFS in the | 1836 | /* If there's an invisible character at position POS + TEST_OFFS in the |
diff --git a/src/marker.c b/src/marker.c index febdb17689a..05e5bb87474 100644 --- a/src/marker.c +++ b/src/marker.c | |||
| @@ -507,7 +507,11 @@ set_marker_internal (Lisp_Object marker, Lisp_Object position, | |||
| 507 | charpos = clip_to_bounds | 507 | charpos = clip_to_bounds |
| 508 | (restricted ? BUF_BEGV (b) : BUF_BEG (b), charpos, | 508 | (restricted ? BUF_BEGV (b) : BUF_BEG (b), charpos, |
| 509 | restricted ? BUF_ZV (b) : BUF_Z (b)); | 509 | restricted ? BUF_ZV (b) : BUF_Z (b)); |
| 510 | if (bytepos == -1) | 510 | /* Don't believe BYTEPOS if it comes from a different buffer, |
| 511 | since that buffer might have a very different correspondence | ||
| 512 | between character and byte positions. */ | ||
| 513 | if (bytepos == -1 | ||
| 514 | || !(MARKERP (position) && XMARKER (position)->buffer == b)) | ||
| 511 | bytepos = buf_charpos_to_bytepos (b, charpos); | 515 | bytepos = buf_charpos_to_bytepos (b, charpos); |
| 512 | else | 516 | else |
| 513 | bytepos = clip_to_bounds | 517 | bytepos = clip_to_bounds |