From: Dmitry Antipov Date: Fri, 14 Sep 2012 14:23:50 +0000 (+0400) Subject: Avoid out-of-range marker position (Bug#12426). X-Git-Tag: emacs-24.2.90~274^2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=2f294edf3a601c612e0a4c208539e842d790a894;p=emacs.git Avoid out-of-range marker position (Bug#12426). * insdel.c (replace_range, replace_range_2): Adjust markers before overlays, as suggested by comments. (insert_1_both, insert_from_buffer_1, adjust_after_replace): Remove redundant check before calling offset_intervals. --- diff --git a/src/ChangeLog b/src/ChangeLog index 5cda8241916..27698886079 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2012-09-14 Dmitry Antipov + + Avoid out-of-range marker position (Bug#12426). + * insdel.c (replace_range, replace_range_2): Adjust + markers before overlays, as suggested by comments. + (insert_1_both, insert_from_buffer_1, adjust_after_replace): + Remove redundant check before calling offset_intervals. + 2012-09-14 Martin Rudalics * xdisp.c (Fformat_mode_line): Unconditionally save/restore diff --git a/src/insdel.c b/src/insdel.c index b12a390633e..bfb2327a696 100644 --- a/src/insdel.c +++ b/src/insdel.c @@ -840,8 +840,7 @@ insert_1_both (const char *string, PT + nchars, PT_BYTE + nbytes, before_markers); - if (buffer_intervals (current_buffer)) - offset_intervals (current_buffer, PT, nchars); + offset_intervals (current_buffer, PT, nchars); if (!inherit && buffer_intervals (current_buffer)) set_text_properties (make_number (PT), make_number (PT + nchars), @@ -1153,8 +1152,7 @@ insert_from_buffer_1 (struct buffer *buf, PT_BYTE + outgoing_nbytes, 0); - if (buffer_intervals (current_buffer)) - offset_intervals (current_buffer, PT, nchars); + offset_intervals (current_buffer, PT, nchars); /* Get the intervals for the part of the string we are inserting. */ intervals = buffer_intervals (buf); @@ -1222,8 +1220,7 @@ adjust_after_replace (ptrdiff_t from, ptrdiff_t from_byte, else if (len < nchars_del) adjust_overlays_for_delete (from, nchars_del - len); - if (buffer_intervals (current_buffer)) - offset_intervals (current_buffer, from, len - nchars_del); + offset_intervals (current_buffer, from, len - nchars_del); if (from < PT) adjust_point (len - nchars_del, len_byte - nbytes_del); @@ -1394,16 +1391,16 @@ replace_range (ptrdiff_t from, ptrdiff_t to, Lisp_Object new, eassert (GPT <= GPT_BYTE); - /* Adjust the overlay center as needed. This must be done after - adjusting the markers that bound the overlays. */ - adjust_overlays_for_delete (from, nchars_del); - adjust_overlays_for_insert (from, inschars); - /* Adjust markers for the deletion and the insertion. */ if (markers) adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, inschars, outgoing_insbytes); + /* Adjust the overlay center as needed. This must be done after + adjusting the markers that bound the overlays. */ + adjust_overlays_for_delete (from, nchars_del); + adjust_overlays_for_insert (from, inschars); + offset_intervals (current_buffer, from, inschars - nchars_del); /* Get the intervals for the part of the string we are inserting-- @@ -1510,6 +1507,12 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte, eassert (GPT <= GPT_BYTE); + /* Adjust markers for the deletion and the insertion. */ + if (markers + && ! (nchars_del == 1 && inschars == 1 && nbytes_del == insbytes)) + adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, + inschars, insbytes); + /* Adjust the overlay center as needed. This must be done after adjusting the markers that bound the overlays. */ if (nchars_del != inschars) @@ -1518,12 +1521,6 @@ replace_range_2 (ptrdiff_t from, ptrdiff_t from_byte, adjust_overlays_for_delete (from + inschars, nchars_del); } - /* Adjust markers for the deletion and the insertion. */ - if (markers - && ! (nchars_del == 1 && inschars == 1 && nbytes_del == insbytes)) - adjust_markers_for_replace (from, from_byte, nchars_del, nbytes_del, - inschars, insbytes); - offset_intervals (current_buffer, from, inschars - nchars_del); /* Relocate point as if it were a marker. */