changeset 2777:40e00789f1c1

* cmds.c (Fforward_char): Check proposed new position, and then set point, instead of setting point to a potentially invalid position.
author Jim Blandy <jimb@redhat.com>
date Fri, 14 May 1993 14:37:53 +0000
parents 8bf3bb4c20dd
children 071fa2f469d7
files src/cmds.c
diffstat 1 files changed, 22 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/cmds.c	Fri May 14 14:36:01 1993 +0000
+++ b/src/cmds.c	Fri May 14 14:37:53 1993 +0000
@@ -41,17 +41,28 @@
   else
     CHECK_NUMBER (n, 0);
 
-  SET_PT (point + XINT (n));
-  if (point < BEGV)
-    {
-      SET_PT (BEGV);
-      Fsignal (Qbeginning_of_buffer, Qnil);
-    }
-  if (point > ZV)
-    {
-      SET_PT (ZV);
-      Fsignal (Qend_of_buffer, Qnil);
-    }
+  /* This used to just set point to point + XINT (n), and then check
+     to see if it was within boundaries.  But now that SET_PT can
+     potentially do a lot of stuff (calling entering and exiting
+     hooks, etcetera), that's not a good approach.  So we validate the
+     proposed position, then set point.  */
+  {
+    int new_point = point + XINT (n);
+
+    if (new_point < BEGV)
+      {
+	SET_PT (BEGV);
+	Fsignal (Qbeginning_of_buffer, Qnil);
+      }
+    if (new_point > ZV)
+      {
+	SET_PT (ZV);
+	Fsignal (Qend_of_buffer, Qnil);
+      }
+
+    SET_PT (new_point);
+  }
+
   return Qnil;
 }