From 660e941235d0e4e8490d53ad06cdb1e5699634fa Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 18 Dec 2022 10:29:34 +0200 Subject: [PATCH] Avoid crashes in PGTK build due to signal in 'note_mouse_highlight' * 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/xdisp.c b/src/xdisp.c index 45da4966907..06c8b7730cd 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -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; } -- 2.39.5