aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2019-07-02 18:54:36 -0400
committerStefan Monnier2019-07-02 18:54:36 -0400
commit9836030ddaa72c4c594bb64741ecfee6d0d2bcff (patch)
treeb34e1866fdb4114718136f135d3d9f4e3d3e3a42
parentfe3676fe18577643d9d247db2e6c32691f3acf80 (diff)
downloademacs-9836030ddaa72c4c594bb64741ecfee6d0d2bcff.tar.gz
emacs-9836030ddaa72c4c594bb64741ecfee6d0d2bcff.zip
* src/json.c (Fjson_insert): Don't temporarily insert invalid bytes in buffer
-rw-r--r--src/json.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/json.c b/src/json.c
index 607b8d32646..21c4b946b4e 100644
--- a/src/json.c
+++ b/src/json.c
@@ -739,9 +739,6 @@ usage: (json-insert OBJECT &rest ARGS) */)
739 ptrdiff_t inserted_bytes = data.inserted_bytes; 739 ptrdiff_t inserted_bytes = data.inserted_bytes;
740 if (inserted_bytes > 0) 740 if (inserted_bytes > 0)
741 { 741 {
742 /* Make the inserted text part of the buffer, as unibyte text. */
743 insert_from_gap_1 (inserted_bytes, inserted_bytes, false);
744
745 /* If required, decode the stuff we've read into the gap. */ 742 /* If required, decode the stuff we've read into the gap. */
746 struct coding_system coding; 743 struct coding_system coding;
747 /* JSON strings are UTF-8 encoded strings. If for some reason 744 /* JSON strings are UTF-8 encoded strings. If for some reason
@@ -753,17 +750,19 @@ usage: (json-insert OBJECT &rest ARGS) */)
753 !NILP (BVAR (current_buffer, enable_multibyte_characters)); 750 !NILP (BVAR (current_buffer, enable_multibyte_characters));
754 if (CODING_MAY_REQUIRE_DECODING (&coding)) 751 if (CODING_MAY_REQUIRE_DECODING (&coding))
755 { 752 {
756 move_gap_both (PT, PT_BYTE); 753 /* Now we have all the new bytes at the beginning of the gap,
757 GAP_SIZE += inserted_bytes; 754 but `decode_coding_gap` needs them at the end of the gap, so
758 ZV_BYTE -= inserted_bytes; 755 we need to move them. */
759 Z_BYTE -= inserted_bytes; 756 memmove (GAP_END_ADDR - inserted_bytes, GPT_ADDR, inserted_bytes);
760 ZV -= inserted_bytes;
761 Z -= inserted_bytes;
762 decode_coding_gap (&coding, inserted_bytes); 757 decode_coding_gap (&coding, inserted_bytes);
763 inserted = coding.produced_char; 758 inserted = coding.produced_char;
764 } 759 }
765 else 760 else
766 { 761 {
762 /* Make the inserted text part of the buffer, as unibyte text. */
763 eassert (NILP (BVAR (current_buffer, enable_multibyte_characters)));
764 insert_from_gap_1 (inserted_bytes, inserted_bytes, false);
765
767 /* The target buffer is unibyte, so we don't need to decode. */ 766 /* The target buffer is unibyte, so we don't need to decode. */
768 invalidate_buffer_caches (current_buffer, 767 invalidate_buffer_caches (current_buffer,
769 PT, PT + inserted_bytes); 768 PT, PT + inserted_bytes);