aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
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/coding.c
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/coding.c')
-rw-r--r--src/coding.c12
1 files changed, 8 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;