Subject: bug#70122: 29.3.50; transpose-regions can crash Emacs

From: Eli Zaretskii <[email-masked]>
Date: Mon, 01 Apr 2024 14:55:21 +0300

> From: Braun Gábor <[email-masked]>
> Date: Mon, 01 Apr 2024 12:02:35 +0200
> 
> I have the following file:
> 
> File ~/.emacs.d/trans-regions-bug.el:
> 
> (with-temp-buffer
>   (insert (propertize "a" 'face 'font-lock-variable-name-face))
>   (insert ":\n")
>   (insert (propertize "b" 'face 'font-lock-variable-name-face))
>   (insert ": \x2113\x2080\n")
>   (insert (propertize "v" 'face 'font-lock-variable-name-face))
>   (insert ": scaling\n")
>   ;; Move last line to the beginning
>   (transpose-regions 1 1 10 21))
> 
> End of file ~/.emacs.d/trans-regions-bug.el:
> 
> 
> After building Emacs as described in the INSTALL file, the following
> command crashes Emacs:
> 
>   src/emacs -Q --batch -l ~/.emacs.d/trans-regions-bug.el
> 
> The following appears:
> 
> Fatal error 11: Segmentation fault
> 
> 
> See below for debugging information.
> 
> Please find attached a patch to transpose-regions
> with added tests.  (The patch intends to fix typos:
> makes sure lengths in bytes and characters are not confused.

Thanks, but could you please show the minimal change required to fix
just the particular problem with this scenario (and perhaps explain
the reason for the crash in words), without any cleanup and
typo/confusion fixes?  That would make it easier to review the patch,
whereas with what you sent, it is hard to understand what exactly is
being fixed.

> One case (likely for optimization only) has been removed,
> seemed too much trouble to get it right.)

If you explain the reason for the crash, perhaps we could leave the
optimization alone.