[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Questionable code in handling of wordend in the regexp engine in reg
From: |
Alan Mackenzie |
Subject: |
Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c |
Date: |
Fri, 1 Mar 2019 14:58:56 +0000 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
Hello, Eli.
On Fri, Mar 01, 2019 at 16:43:38 +0200, Eli Zaretskii wrote:
> > Date: Fri, 1 Mar 2019 14:14:48 +0000
> > From: Alan Mackenzie <address@hidden>
> > Cc: address@hidden, address@hidden
> > > buf_bytepos_to_charpos is not supposed to be called when the byte
> > > position is in the middle of a multibyte sequence. We have the
> > > CHAR_HEAD_P, BYTES_BY_CHAR_HEAD, and related macros for that.
> > Thanks, I didn't know that. Maybe we should put an assert into the code,
> > like Stefan suggested.
> We could try.
How about this, as a first approximation?
diff --git a/src/marker.c b/src/marker.c
index 36d6b10c74..9faeca49f4 100644
--- a/src/marker.c
+++ b/src/marker.c
@@ -311,7 +311,8 @@ buf_charpos_to_bytepos (struct buffer *b, ptrdiff_t charpos)
} \
}
-/* Return the character position corresponding to BYTEPOS in B. */
+/* Return the character position corresponding to BYTEPOS in B.
+ BYTEPOS must be at a character boundary. */
ptrdiff_t
buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
@@ -370,6 +371,8 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
best_below++;
BUF_INC_POS (b, best_below_byte);
}
+ /* Check BYTEPOS was at a character boundary. */
+ eassert (best_below_byte == bytepos);
/* If this position is quite far from the nearest known position,
cache the correspondence by creating a marker here.
@@ -397,6 +400,8 @@ buf_bytepos_to_charpos (struct buffer *b, ptrdiff_t bytepos)
best_above--;
BUF_DEC_POS (b, best_above_byte);
}
+ /* Check BYTEPOS was at a character boundary. */
+ eassert (best_above_byte == bytepos);
/* If this position is quite far from the nearest known position,
cache the correspondence by creating a marker here.
--
Alan Mackenzie (Nuremberg, Germany).
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Stefan Monnier, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c,
Alan Mackenzie <=
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/01
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/02
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/02
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/02
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Alan Mackenzie, 2019/03/02
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/02
- Re: Questionable code in handling of wordend in the regexp engine in regex-emacs.c, Eli Zaretskii, 2019/03/04