(buf_bytepos_to_charpos): Fix mixup introduced in commit b300052fb4

Backport of commit 1b595b4598e7 since it turns out this "minor typo"
had disastrous consequences in pathological cases and explains
some of the problems seen in bug#71644 and bug#63040.

* src/marker.c (buf_bytepos_to_charpos): Don't compare byte-positions
with char-positions.
This commit is contained in:
Stefan Monnier 2024-06-27 15:36:28 -04:00
parent 48f4c9cbbc
commit 83234cc1db

View file

@ -358,11 +358,11 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
{
CONSIDER (tail->bytepos, tail->charpos);
/* If we are down to a range of 50 chars,
/* If we are down to a range of DISTANCE bytes,
don't bother checking any other markers;
scan the intervening chars directly now. */
if (best_above - bytepos < distance
|| bytepos - best_below < distance)
if (best_above_byte - bytepos < distance
|| bytepos - best_below_byte < distance)
break;
else
distance += BYTECHAR_DISTANCE_INCREMENT;