From: Eli Zaretskii <eliz@gnu.org>
Date: Wed, 9 Nov 2022 14:25:02 +0000 (+0200)
Subject: Avoid assertion violations in matrix_row
X-Git-Tag: emacs-29.0.90~1616^2~226
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=85b0587a93bdb80c4c304a39cb5ffd3600c95a16;p=emacs.git

Avoid assertion violations in matrix_row

* src/xdisp.c (cursor_in_mouse_face_p): Avoid rare assertion
violations when the cursor's VPOS winds up being invalid for the
window.  (Bug#59147)
---

diff --git a/src/xdisp.c b/src/xdisp.c
index 95da704a070..f6a279636a0 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -33564,8 +33564,14 @@ coords_in_mouse_face_p (struct window *w, int hpos, int vpos)
 bool
 cursor_in_mouse_face_p (struct window *w)
 {
-  int hpos = w->phys_cursor.hpos;
   int vpos = w->phys_cursor.vpos;
+
+  /* If the cursor is outside the matrix glyph rows, it cannot be
+     within the mouse face.  */
+  if (!(0 <= vpos && vpos < w->current_matrix->nrows))
+    return false;
+
+  int hpos = w->phys_cursor.hpos;
   struct glyph_row *row = MATRIX_ROW (w->current_matrix, vpos);
 
   /* When the window is hscrolled, cursor hpos can legitimately be out