unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Petteri Hintsanen <petterih@iki.fi>
Cc: 61887@debbugs.gnu.org
Subject: bug#61887: 30.0.50; Segfault on revert-buffer-with-coding-system
Date: Fri, 03 Mar 2023 18:56:11 -0500	[thread overview]
Message-ID: <jwvh6v1v1hm.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <jwvo7p9v684.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Fri, 03 Mar 2023 18:19:47 -0500")

> But yes, there's something funny going on in `set_intervals_multibyte_1`.

I think I found it: when `total_length` is 0, we call `delete_interval (i)`
but that only deletes the interval represented by the node itself rather
than the whole subtree, so we may end up keeping subtrees of `i`.
Not only that's wrong since `total_length == 0` means there should be
nothing at all, but we don't even recurse on those subtrees so
they keep using the positions of the old mode.

In my case some call `delete_interval (i)` ended up replacing the node
of `total_length == 0` with an old subnode of length 2!

The patch below seems to fix it.


        Stefan


diff --git a/src/intervals.c b/src/intervals.c
index 75e37a8c90c..6f6a0c94cf5 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -2333,6 +2333,9 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
 
   if (TOTAL_LENGTH (i) == 0)
     {
+      /* Delete the whole subtree.  */
+      i->left = NULL;
+      i->right = NULL;
       delete_interval (i);
       return;
     }
@@ -2355,7 +2358,8 @@ set_intervals_multibyte_1 (INTERVAL i, bool multi_flag,
 	  left_end_byte = CHAR_TO_BYTE (left_end);
 	}
 
-      set_intervals_multibyte_1 (i->left, multi_flag, start, start_byte,
+      set_intervals_multibyte_1 (i->left, multi_flag,
+				 start, start_byte,
 				 left_end, left_end_byte);
     }
   if (i->right)






  reply	other threads:[~2023-03-03 23:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-28 21:48 bug#61887: 30.0.50; Segfault on revert-buffer-with-coding-system Petteri Hintsanen
2023-03-01 12:47 ` Eli Zaretskii
2023-03-03 23:19 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-03 23:56   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-03-04  0:13     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-04  7:30       ` Eli Zaretskii
2023-09-06  0:03         ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvh6v1v1hm.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=61887@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=petterih@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).