aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2016-06-22 18:41:13 +0300
committerEli Zaretskii2016-06-22 18:41:13 +0300
commit791193d309a0e8f60c3cdae2941c718d07411159 (patch)
tree59fd8c49bbad4a7e2fcdf63802a20ec13c770b41 /src
parentbbc58feac57d070a3b645b7a132ee3f3624b6ddd (diff)
downloademacs-791193d309a0e8f60c3cdae2941c718d07411159.tar.gz
emacs-791193d309a0e8f60c3cdae2941c718d07411159.zip
Fix 'insert-file-contents' when REPLACE is non-nil
* src/fileio.c (maybe_move_gap): New function to move the gap to the end of a buffer, if it isn't there already. (Finsert_file_contents): Call 'maybe_move_gap' before using conversion_buffer's text as a C 'char' array. (Bug#23659) * src/coding.c (decode_eol): Compute the byte increment before calling del_range_2, because the latter can invalidate the pointer to buffer text.
Diffstat (limited to 'src')
-rw-r--r--src/coding.c12
-rw-r--r--src/fileio.c16
2 files changed, 24 insertions, 4 deletions
diff --git a/src/coding.c b/src/coding.c
index 804b628d3be..29c90f0a401 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6826,7 +6826,14 @@ decode_eol (struct coding_system *coding)
6826 6826
6827 while (pos_byte < pos_end) 6827 while (pos_byte < pos_end)
6828 { 6828 {
6829 int incr;
6830
6829 p = BYTE_POS_ADDR (pos_byte); 6831 p = BYTE_POS_ADDR (pos_byte);
6832 if (coding->dst_multibyte)
6833 incr = BYTES_BY_CHAR_HEAD (*p);
6834 else
6835 incr = 1;
6836
6830 if (*p == '\r' && p[1] == '\n') 6837 if (*p == '\r' && p[1] == '\n')
6831 { 6838 {
6832 del_range_2 (pos, pos_byte, pos + 1, pos_byte + 1, 0); 6839 del_range_2 (pos, pos_byte, pos + 1, pos_byte + 1, 0);
@@ -6834,10 +6841,7 @@ decode_eol (struct coding_system *coding)
6834 pos_end--; 6841 pos_end--;
6835 } 6842 }
6836 pos++; 6843 pos++;
6837 if (coding->dst_multibyte) 6844 pos_byte += incr;
6838 pos_byte += BYTES_BY_CHAR_HEAD (*p);
6839 else
6840 pos_byte++;
6841 } 6845 }
6842 coding->produced -= n; 6846 coding->produced -= n;
6843 coding->produced_char -= n; 6847 coding->produced_char -= n;
diff --git a/src/fileio.c b/src/fileio.c
index facc4bef927..b1f9d3cf73a 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -3359,6 +3359,21 @@ restore_window_points (Lisp_Object window_markers, ptrdiff_t inserted,
3359 } 3359 }
3360} 3360}
3361 3361
3362/* Make sure the gap is at Z_BYTE. This is required to treat buffer
3363 text as a linear C char array. */
3364static void
3365maybe_move_gap (struct buffer *b)
3366{
3367 if (BUF_GPT_BYTE (b) != BUF_Z_BYTE (b))
3368 {
3369 struct buffer *cb = current_buffer;
3370
3371 set_buffer_internal (b);
3372 move_gap_both (Z, Z_BYTE);
3373 set_buffer_internal (cb);
3374 }
3375}
3376
3362/* FIXME: insert-file-contents should be split with the top-level moved to 3377/* FIXME: insert-file-contents should be split with the top-level moved to
3363 Elisp and only the core kept in C. */ 3378 Elisp and only the core kept in C. */
3364 3379
@@ -3942,6 +3957,7 @@ by calling `format-decode', which see. */)
3942 3957
3943 coding_system = CODING_ID_NAME (coding.id); 3958 coding_system = CODING_ID_NAME (coding.id);
3944 set_coding_system = true; 3959 set_coding_system = true;
3960 maybe_move_gap (XBUFFER (conversion_buffer));
3945 decoded = BUF_BEG_ADDR (XBUFFER (conversion_buffer)); 3961 decoded = BUF_BEG_ADDR (XBUFFER (conversion_buffer));
3946 inserted = (BUF_Z_BYTE (XBUFFER (conversion_buffer)) 3962 inserted = (BUF_Z_BYTE (XBUFFER (conversion_buffer))
3947 - BUF_BEG_BYTE (XBUFFER (conversion_buffer))); 3963 - BUF_BEG_BYTE (XBUFFER (conversion_buffer)));