Subject: bug#5131: Subject: 23.1; interaction of transpose-regions with markers and multibyte chars

From: [email-masked]
Date: Sun, 17 Jul 2016 00:46:34 -0400

Andrew Hyatt <[email-masked]> writes:

> Sorry for the late reply.  I can reproduce the problem of unexpected
> characters when transposing using markers in Emacs 25.
>
> [email-masked] writes:
>
>> ;-*- mode: lisp-interaction; coding: utf-8-unix -*-
>>
>> ; case 1: abcd      was: abcd
>> ; case 2: ÷bcd      was: ÷bcd
>> ; case 3: ÷ab"äé    was: ÷ab"äé
>>
>> (progn (defvar start nil) (defvar len nil)) ;do \C-j here
>>
>> ; Using markers to move multi-byte characters may cause problems
>>
>> (progn (setq begm (make-marker)) (setq endm (make-marker))) ;do \C-j here
>>
>> (defun reverse-all ()
>> (set-marker begm start)
>> (set-marker endm (+ start (1- len)))
>>  (while (> endm begm)
>> (progn (transpose-regions begm (1+ begm) endm (1+ endm) t)
>>  (set-marker begm (1+ begm))
>>  (set-marker endm (1- endm))))) ;do \C-j here
>>
>> ;case1
>> (progn (setq start 64) (setq len 4) (reverse-all)) ;do \C-j here
>>
>> ;case2
>> (progn (setq start 94) (setq len 4) (reverse-all)) ;do \C-j here
>>
>> ;case3
>> (progn (setq start 124) (setq len 6) (reverse-all)) ;do \C-j here

With the latest emacs-25 branch after evaluating up to case3 here, I get
an abort, here is the backtrace:

(gdb) bt
#0  0x00007ffff1218d59 in raise () from /usr/lib/libpthread.so.0
#1  0x00000000005738c4 in terminate_due_to_signal (sig=6, backtrace_limit=2147483647) at emacs.c:381
#2  0x0000000000600d84 in die (msg=0x6f4140 "IT_BYTEPOS (*it) == CHAR_TO_BYTE (IT_CHARPOS (*it))", file=0x6f1ff0 "xdisp.c", 
    line=7442) at alloc.c:7223
#3  0x0000000000452c1c in set_iterator_to_next (it=0x7fffffff90f0, reseat_p=true) at xdisp.c:7442
#4  0x00000000004832b4 in display_line (it=0x7fffffff90f0) at xdisp.c:20997
#5  0x00000000004793af in try_window_id (w=0x13fc690) at xdisp.c:18413
#6  0x000000000046fd44 in redisplay_window (window=20956821, just_this_one_p=true) at xdisp.c:16573
#7  0x0000000000467ad2 in redisplay_window_1 (window=20956821) at xdisp.c:14454
#8  0x0000000000621077 in internal_condition_case_1 (bfun=0x467a90 <redisplay_window_1>, arg=20956821, handlers=14478067, 
    hfun=0x467a0a <redisplay_window_error>) at eval.c:1333
#9  0x0000000000466cbc in redisplay_internal () at xdisp.c:14079
#10 0x00000000004640c2 in redisplay () at xdisp.c:13214
#11 0x000000000057b647 in read_char (commandflag=1, map=17541507, prev_event=0, used_mouse_menu=0x7fffffffe42f, end_time=0x0)
    at keyboard.c:2477
#12 0x000000000058b90f in read_key_sequence (keybuf=0x7fffffffe5e0, bufsize=30, prompt=0, dont_downcase_last=false, 
    can_return_switch_frame=true, fix_current_buffer=true, prevent_redisplay=false) at keyboard.c:9063
#13 0x000000000057854d in command_loop_1 () at keyboard.c:1365
#14 0x0000000000620fdd in internal_condition_case (bfun=0x57810b <command_loop_1>, handlers=19056, hfun=0x577779 <cmd_error>)
    at eval.c:1309
#15 0x0000000000577d38 in command_loop_2 (ignore=0) at keyboard.c:1107
#16 0x000000000062056f in internal_catch (tag=45840, func=0x577d0f <command_loop_2>, arg=0) at eval.c:1074
#17 0x0000000000577cda in command_loop () at keyboard.c:1086
#18 0x0000000000577251 in recursive_edit_1 () at keyboard.c:692
#19 0x000000000057745d in Frecursive_edit () at keyboard.c:763
#20 0x00000000005751f5 in main (argc=3, argv=0x7fffffffea78) at emacs.c:1606

Lisp Backtrace:
"redisplay_internal (C function)" (0x0)

In GNU Emacs 25.0.95.21 (x86_64-unknown-linux-gnu, X toolkit)
 of 2016-07-11 built on zony
Repository revision: d1300340cbd44abe79ef71a57ae1488479f76b0d
Windowing system distributor 'The X.Org Foundation', version 11.0.11803000
Configured using:
 'configure --cache-file=../debug-config.cache 'CFLAGS=-O0 -g3
 -march=native' --enable-checking MAKEINFO=makeinfo-4.13a
 --with-x-toolkit=lucid --without-toolkit-scroll-bars --with-gif=no
 --with-jpeg=no'