unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org
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	[thread overview]
Message-ID: <20190301145856.GE5674@ACM> (raw)
In-Reply-To: <834l8mirj9.fsf@gnu.org>

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 <acm@muc.de>
> > Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org

> > > 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).



  reply	other threads:[~2019-03-01 14:58 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-22 16:45 Questionable code in handling of wordend in the regexp engine in regex-emacs.c Alan Mackenzie
2019-02-23 23:15 ` Stefan Monnier
2019-02-25 18:56   ` Alan Mackenzie
2019-02-25 19:18     ` Stefan Monnier
2019-03-01 11:10       ` Alan Mackenzie
2019-03-01 13:41         ` Stefan Monnier
2019-03-01 13:46         ` Eli Zaretskii
2019-03-01 14:14           ` Alan Mackenzie
2019-03-01 14:43             ` Eli Zaretskii
2019-03-01 14:58               ` Alan Mackenzie [this message]
2019-03-01 16:22                 ` Eli Zaretskii
2019-03-01 16:38                   ` Alan Mackenzie
2019-03-01 19:16                     ` Alan Mackenzie
2019-03-01 19:31                       ` Eli Zaretskii
2019-03-02 11:16                         ` Alan Mackenzie
2019-03-02 12:18                           ` Eli Zaretskii
2019-03-02 13:18                             ` Alan Mackenzie
2019-03-02 13:37                               ` Eli Zaretskii
2019-03-04 17:25                               ` Eli Zaretskii
2019-03-05 10:51                                 ` Alan Mackenzie
2019-03-05 16:26                                   ` Eli Zaretskii
2019-03-02 12:21                           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190301145856.GE5674@ACM \
    --to=acm@muc.de \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).