]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid crashes in PGTK build due to signal in 'note_mouse_highlight'
authorEli Zaretskii <eliz@gnu.org>
Sun, 18 Dec 2022 08:29:34 +0000 (10:29 +0200)
committerEli Zaretskii <eliz@gnu.org>
Sun, 18 Dec 2022 08:29:34 +0000 (10:29 +0200)
* src/xdisp.c (string_buffer_position): Make sure the TO argument
of 'string_buffer_position_lim' is always inside [BEGV..ZV].
Otherwise 'string_buffer_position_lim' might call
'get-char-property' and friends with invalid position, which will
just signal an error and do nothing useful.  (Bug#60144)

src/xdisp.c

index 45da4966907ac86d562f4467d2f07aacf6244989..06c8b7730cdbe414e50dbd895f4d9b959294724d 100644 (file)
@@ -6281,13 +6281,16 @@ static ptrdiff_t
 string_buffer_position (Lisp_Object string, ptrdiff_t around_charpos)
 {
   const int MAX_DISTANCE = 1000;
+  ptrdiff_t forward_limit = min (around_charpos + MAX_DISTANCE, ZV);
   ptrdiff_t found = string_buffer_position_lim (string, around_charpos,
-                                               around_charpos + MAX_DISTANCE,
-                                               false);
+                                               forward_limit, false);
 
   if (!found)
-    found = string_buffer_position_lim (string, around_charpos,
-                                       around_charpos - MAX_DISTANCE, true);
+    {
+      ptrdiff_t backward_limit = max (around_charpos - MAX_DISTANCE, BEGV);
+      found = string_buffer_position_lim (string, around_charpos,
+                                         backward_limit, true);
+    }
   return found;
 }