diff --git a/src/marker.c b/src/marker.c index 3c8e628762e..9727586f424 100644 --- a/src/marker.c +++ b/src/marker.c @@ -214,11 +214,12 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) We have one known above and one known below. Scan, counting characters, from whichever one is closer. */ + eassert (best_below <= charpos && charpos <= best_above); if (charpos - best_below < best_above - charpos) { bool record = charpos - best_below > 5000; - while (best_below != charpos) + while (best_below < charpos) { best_below++; best_below_byte += buf_next_char_len (b, best_below_byte); @@ -243,7 +244,7 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos) { bool record = best_above - charpos > 5000; - while (best_above != charpos) + while (best_above > charpos) { best_above--; best_above_byte -= buf_prev_char_len (b, best_above_byte); diff --git a/src/xdisp.c b/src/xdisp.c index 65d9221a159..2bedf1c7847 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -19449,7 +19449,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p) { ptrdiff_t cur, next, found, max = 0, threshold; threshold = XFIXNUM (Vlong_line_threshold); - for (cur = 1; cur < Z; cur = next) + for (cur = BEG; cur < Z; cur = next) { next = find_newline1 (cur, CHAR_TO_BYTE (cur), 0, -1, 1, &found, NULL, true);