From 954c9c5bc344cdd6b201c2260b306ec0999aff24 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sat, 2 Mar 2019 18:23:34 +0000 Subject: [PATCH] Check by eassert that a bytepos argument isn't in the middle of a character * src/marker.c (buf_bytepos_to_charpos): Add an eassert to check that the parameter bytepos is at the beginning of a character or EOB. --- src/marker.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/marker.c b/src/marker.c index b58051a8c2b..0b2e1bf5c6b 100644 --- a/src/marker.c +++ b/src/marker.c @@ -332,6 +332,10 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos) if (best_above == best_above_byte) return bytepos; + /* Check bytepos is not in the middle of a character. */ + eassert (bytepos >= BUF_Z_BYTE (b) + || CHAR_HEAD_P (BUF_FETCH_BYTE (b, bytepos))); + best_below = BEG; best_below_byte = BEG_BYTE; -- 2.39.2