From: Eli Zaretskii Date: Fri, 15 Jun 2018 08:27:56 +0000 (+0300) Subject: Fix 'replace-buffer-contents' in multibyte buffers X-Git-Tag: emacs-26.1.90~355 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0d3c35807d0b0a3aaa4c4ebd2f040bb78013879d;p=emacs.git 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. --- diff --git a/src/editfns.c b/src/editfns.c index b553a213e6c..fc5b6c117f5 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -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); } diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el index 714e92e5053..ec411ff773b 100644 --- a/test/src/editfns-tests.el +++ b/test/src/editfns-tests.el @@ -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