all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Juanma Barranquero <lekktu@gmail.com>, 17298@debbugs.gnu.org
Subject: bug#17298: 24.4.50; emacs_backtrace
Date: Sat, 19 Apr 2014 13:55:39 -0400	[thread overview]
Message-ID: <jwv7g6lgqgh.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <831twtgtyo.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 19 Apr 2014 19:33:19 +0300")

> I really wish someone who knows those parts of Emacs would look into
> this problem.

I don't know those parts very well, but it seems that the patch below
might make sense.

I have a hard time believing that we've lived with such a bug for so
many years, but this makes the code agree with the comment, and if you
look at the diagram before the function, I think the comment is right
and the code is wrong.

Just to clarify the crucial part of the patch is:

-  interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);
+  interval->total_length -= B->total_length - TOTAL_LENGTH (c);


-- Stefan


=== modified file 'src/intervals.c'
--- src/intervals.c	2014-01-21 02:28:57 +0000
+++ src/intervals.c	2014-04-19 17:51:01 +0000
@@ -334,10 +334,16 @@
 static INTERVAL
 rotate_right (INTERVAL interval)
 {
-  INTERVAL i;
+  INTERVAL c;
   INTERVAL B = interval->left;
   ptrdiff_t old_total = interval->total_length;
 
+  eassert (TOTAL_LENGTH (interval) > 0);
+  eassert (TOTAL_LENGTH (interval)
+	   > TOTAL_LENGTH (B) + TOTAL_LENGTH (interval->right));
+  eassert (TOTAL_LENGTH (B)
+	   > TOTAL_LENGTH (B->left) + TOTAL_LENGTH (B->right));
+
   /* Deal with any Parent of A;  make it point to B.  */
   if (! ROOT_INTERVAL_P (interval))
     {
@@ -348,23 +354,23 @@
     }
   copy_interval_parent (B, interval);
 
-  /* Make B the parent of A */
-  i = B->right;
+  /* Make B the parent of A.  */
+  c = B->right;
   set_interval_right (B, interval);
   set_interval_parent (interval, B);
 
-  /* Make A point to c */
-  set_interval_left (interval, i);
-  if (i)
-    set_interval_parent (i, interval);
+  /* Make A point to c.  */
+  set_interval_left (interval, c);
+  if (c)
+    set_interval_parent (c, interval);
 
   /* A's total length is decreased by the length of B and its left child.  */
-  interval->total_length -= B->total_length - LEFT_TOTAL_LENGTH (interval);
-  eassert (TOTAL_LENGTH (interval) >= 0);
+  interval->total_length -= B->total_length - TOTAL_LENGTH (c);
+  eassert (TOTAL_LENGTH (interval) > 0);
 
   /* B must have the same total length of A.  */
   B->total_length = old_total;
-  eassert (TOTAL_LENGTH (B) >= 0);
+  eassert (TOTAL_LENGTH (B) > 0);
 
   return B;
 }
@@ -381,7 +387,7 @@
 static INTERVAL
 rotate_left (INTERVAL interval)
 {
-  INTERVAL i;
+  INTERVAL c;
   INTERVAL B = interval->right;
   ptrdiff_t old_total = interval->total_length;
 
@@ -395,23 +401,23 @@
     }
   copy_interval_parent (B, interval);
 
-  /* Make B the parent of A */
-  i = B->left;
+  /* Make B the parent of A.  */
+  c = B->left;
   set_interval_left (B, interval);
   set_interval_parent (interval, B);
 
-  /* Make A point to c */
-  set_interval_right (interval, i);
-  if (i)
-    set_interval_parent (i, interval);
+  /* Make A point to c.  */
+  set_interval_right (interval, c);
+  if (c)
+    set_interval_parent (c, interval);
 
   /* A's total length is decreased by the length of B and its right child.  */
-  interval->total_length -= B->total_length - RIGHT_TOTAL_LENGTH (interval);
-  eassert (TOTAL_LENGTH (interval) >= 0);
+  interval->total_length -= B->total_length - TOTAL_LENGTH (c);
+  eassert (TOTAL_LENGTH (interval) > 0);
 
   /* B must have the same total length of A.  */
   B->total_length = old_total;
-  eassert (TOTAL_LENGTH (B) >= 0);
+  eassert (TOTAL_LENGTH (B) > 0);
 
   return B;
 }






  reply	other threads:[~2014-04-19 17:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-19 14:59 bug#17298: 24.4.50; emacs_backtrace Drew Adams
2014-04-19 15:42 ` Juanma Barranquero
2014-04-19 16:33   ` Eli Zaretskii
2014-04-19 17:55     ` Stefan Monnier [this message]
2014-04-21  1:57     ` Stefan Monnier
2014-04-21  7:16       ` Eli Zaretskii

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

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

  git send-email \
    --in-reply-to=jwv7g6lgqgh.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=17298@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=lekktu@gmail.com \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.