Commit 0d3c3580 authored by Eli Zaretskii's avatar Eli Zaretskii

Fix 'replace-buffer-contents' in multibyte buffers

* src/editfns.c (buffer_chars_equal): Pass a byte position to
BUF_FETCH_CHAR_AS_MULTIBYTE, not a character position.
(Bug#31837)

* test/src/editfns-tests.el (replace-buffer-contents-bug31837):
New test.
parent c79a6275
......@@ -3304,8 +3304,17 @@ buffer_chars_equal (struct context *ctx,
eassert (pos_b >= BUF_BEGV (ctx->buffer_b));
eassert (pos_b < BUF_ZV (ctx->buffer_b));
return BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_a, pos_a)
== BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_b, pos_b);
ptrdiff_t bpos_a =
NILP (BVAR (ctx->buffer_a, enable_multibyte_characters))
? pos_a
: buf_charpos_to_bytepos (ctx->buffer_a, pos_a);
ptrdiff_t bpos_b =
NILP (BVAR (ctx->buffer_b, enable_multibyte_characters))
? pos_b
: buf_charpos_to_bytepos (ctx->buffer_b, pos_b);
return BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_a, bpos_a)
== BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_b, bpos_b);
}
......
......@@ -247,6 +247,17 @@
(buffer-string)
"foo bar baz qux"))))))
(ert-deftest replace-buffer-contents-bug31837 ()
(switch-to-buffer "a")
(insert-char (char-from-name "SMILE"))
(insert "1234")
(switch-to-buffer "b")
(insert-char (char-from-name "SMILE"))
(insert "5678")
(replace-buffer-contents "a")
(should (equal (buffer-substring-no-properties (point-min) (point-max))
(concat (string (char-from-name "SMILE")) "1234"))))
(ert-deftest delete-region-undo-markers-1 ()
"Make sure we don't end up with freed markers reachable from Lisp."
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment