From 5cce13ddd745a4952bf1cdcab348c8db69482ecc Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Mon, 9 Dec 2002 01:56:05 +0000 Subject: [PATCH] (row_containing_pos): Check more carefully whether charpos is really in the row before returning it. --- src/xdisp.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/xdisp.c b/src/xdisp.c index 38df34d7c53..bfe9d4f9637 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -11509,25 +11509,27 @@ row_containing_pos (w, charpos, start, end, dy) last_y = window_text_bottom_y (w) - dy; - while ((end == NULL || row < end) - && MATRIX_ROW_BOTTOM_Y (row) < last_y - && (MATRIX_ROW_END_CHARPOS (row) < charpos + while (1) + { + /* Give up if we have gone too far. */ + if (end && row >= end) + return NULL; + if (MATRIX_ROW_BOTTOM_Y (row) >= last_y) + return NULL; + + /* If it is in this row, return this row. */ + if (! (MATRIX_ROW_END_CHARPOS (row) < charpos || (MATRIX_ROW_END_CHARPOS (row) == charpos /* The end position of a row equals the start position of the next row. If CHARPOS is there, we would rather display it in the next line, except when this line ends in ZV. */ && !row->ends_at_zv_p - && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row)))) - ++row; - - /* Give up if CHARPOS not found. */ - if ((end && row >= end) - || charpos < MATRIX_ROW_START_CHARPOS (row) - || charpos > MATRIX_ROW_END_CHARPOS (row)) - row = NULL; - - return row; + && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row))) + && charpos >= MATRIX_ROW_START_CHARPOS (row)) + return row; + ++row; + } } -- 2.39.2